changeset 15785:e926951e61fe

Don't use g_list_length() and g_slist_length() when all you want to do if check if the list is empty. Those two functions needlessly iterate through the entire list.
author Mark Doliner <mark@kingant.net>
date Tue, 13 Mar 2007 07:19:06 +0000
parents eed84b59c252
children b25acae693cd
files libpurple/protocols/jabber/roster.c libpurple/protocols/jabber/si.c libpurple/protocols/novell/nmuser.c pidgin/gtkimhtmltoolbar.c pidgin/plugins/musicmessaging/musicmessaging.c
diffstat 5 files changed, 11 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/roster.c	Tue Mar 13 06:53:43 2007 +0000
+++ b/libpurple/protocols/jabber/roster.c	Tue Mar 13 07:19:06 2007 +0000
@@ -380,7 +380,7 @@
 	GSList *groups = NULL;
 
 	buddies = g_slist_remove(buddies, buddy);
-	if(g_slist_length(buddies)) {
+	if(buddies != NULL) {
 		GaimBuddy *tmpbuddy;
 		GaimGroup *tmpgroup;
 
--- a/libpurple/protocols/jabber/si.c	Tue Mar 13 06:53:43 2007 +0000
+++ b/libpurple/protocols/jabber/si.c	Tue Mar 13 07:19:06 2007 +0000
@@ -783,7 +783,7 @@
 			return;
 
 		/* XXX: for now, send to the first resource available */
-		if(g_list_length(jb->resources) >= 1) {
+		if(jb->resources != NULL) {
 			char **who_v = g_strsplit(xfer->who, "/", 2);
 			char *who;
 
--- a/libpurple/protocols/novell/nmuser.c	Tue Mar 13 06:53:43 2007 +0000
+++ b/libpurple/protocols/novell/nmuser.c	Tue Mar 13 07:19:06 2007 +0000
@@ -1534,13 +1534,12 @@
 		}
 
 		/* Time to callback? */
-		if (g_slist_length(list) == 0) {
+		if (list == NULL) {
 			nm_response_cb cb = nm_request_get_callback(request);
 
 			if (cb) {
 				cb(user, 0, conference, conference);
 			}
-			g_slist_free(list);
 			nm_release_request(request);
 		}
 	}
--- a/pidgin/gtkimhtmltoolbar.c	Tue Mar 13 06:53:43 2007 +0000
+++ b/pidgin/gtkimhtmltoolbar.c	Tue Mar 13 07:19:06 2007 +0000
@@ -672,7 +672,7 @@
 	gtk_window_set_role(GTK_WINDOW(dialog), "smiley_dialog");
 	gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_MOUSE);
 
-	if (g_slist_length(unique_smileys)) {
+	if (unique_smileys != NULL) {
 		struct smiley_button_list *ls, *it, *it_tmp;
 		GtkWidget *line;
 		int line_width = 0;
--- a/pidgin/plugins/musicmessaging/musicmessaging.c	Tue Mar 13 06:53:43 2007 +0000
+++ b/pidgin/plugins/musicmessaging/musicmessaging.c	Tue Mar 13 07:19:06 2007 +0000
@@ -235,16 +235,19 @@
 static int
 mmconv_from_conv_loc(GaimConversation *conv)
 {
+	GList *l;
 	MMConversation *mmconv_current = NULL;
 	guint i;
 	
-	for (i = 0; i < g_list_length(conversations); i++)
+	i = 0;
+	for (l = conversations; l != NULL; l = l->next)
 	{
-		mmconv_current = (MMConversation *)g_list_nth_data(conversations, i);
+		mmconv_current = l->data;
 		if (conv == mmconv_current->conv)
 		{
 			return i;
 		}
+		i++;
 	}
 	return -1;
 }
@@ -295,9 +298,9 @@
 plugin_unload(GaimPlugin *plugin) {
 	MMConversation *mmconv = NULL;
 	
-	while (g_list_length(conversations) > 0)
+	while (conversations != NULL)
 	{
-		mmconv = g_list_first(conversations)->data;
+		mmconv = conversations->data;
 		conv_destroyed(mmconv->conv);
 	}
 	return TRUE;