diff libpurple/protocols/myspace/message.c @ 24497:f10aba5592c6

The other day while struct hiding, I noticed a for loop that was checking g_list_length() as the loop conditional. I decided to check all our calls to g_list_length() to see which ones I could clean up without too much work.
author Richard Laager <rlaager@wiktel.com>
date Thu, 27 Nov 2008 05:54:09 +0000
parents 9479cf89a97d
children 0e8d91cdd63a
line wrap: on
line diff
--- a/libpurple/protocols/myspace/message.c	Thu Nov 27 05:51:03 2008 +0000
+++ b/libpurple/protocols/myspace/message.c	Thu Nov 27 05:54:09 2008 +0000
@@ -613,6 +613,7 @@
 		const gchar *sep, 
 		const gchar *begin, const gchar *end)
 {
+	int num_items;
 	gchar **strings;
 	gchar **strings_tmp;
 	gchar *joined;
@@ -621,8 +622,10 @@
 
 	g_return_val_if_fail(msg != NULL, NULL);
 
+	num_items = g_list_length(msg);
+
 	/* Add one for NULL terminator for g_strjoinv(). */
-	strings = (gchar **)g_new0(gchar *, g_list_length(msg) + 1);
+	strings = (gchar **)g_new0(gchar *, num_items + 1);
 
 	strings_tmp = strings;
 	g_list_foreach(msg, gf, &strings_tmp);
@@ -632,7 +635,7 @@
 	g_free(joined);
 
 	/* Clean up. */
-	for (i = 0; i < g_list_length(msg); ++i) {
+	for (i = 0; i < num_items; ++i) {
 		g_free(strings[i]);
 	}