Mercurial > pidgin.yaz
changeset 16817:10f175539cfe
Change a few functions to free a linked list while iterating through
it instead of after iterating through it. This is probably a very
tiny bit faster, but more importantly, I think the code is easier to
read
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Thu, 03 May 2007 07:55:32 +0000 |
parents | 04fecd1ee64d |
children | f7466b0379e8 |
files | libpurple/buddyicon.c libpurple/connection.c libpurple/privacy.c libpurple/server.c |
diffstat | 4 files changed, 24 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/buddyicon.c Thu May 03 07:51:51 2007 +0000 +++ b/libpurple/buddyicon.c Thu May 03 07:55:32 2007 +0000 @@ -372,7 +372,7 @@ PurpleAccount *account; const char *username; PurpleBuddyIcon *icon_to_set; - GSList *sl, *list; + GSList *buddies; g_return_if_fail(icon != NULL); @@ -386,11 +386,10 @@ * the icon when they realize it has no data. */ icon_to_set = icon->img ? icon : NULL; - for (list = sl = purple_find_buddies(account, username); - sl != NULL; - sl = sl->next) + buddies = purple_find_buddies(account, username); + while (buddies != NULL) { - PurpleBuddy *buddy = (PurpleBuddy *)sl->data; + PurpleBuddy *buddy = (PurpleBuddy *)buddies->data; char *old_icon; purple_buddy_set_icon(buddy, icon_to_set); @@ -425,10 +424,10 @@ } unref_filename(old_icon); g_free(old_icon); + + buddies = g_slist_delete_link(buddies, buddies); } - g_slist_free(list); - conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, username, account); if (conv != NULL)
--- a/libpurple/connection.c Thu May 03 07:51:51 2007 +0000 +++ b/libpurple/connection.c Thu May 03 07:55:32 2007 +0000 @@ -161,7 +161,7 @@ purple_connection_destroy(PurpleConnection *gc) { PurpleAccount *account; - GSList *buddies, *tmp; + GSList *buddies; #if 0 GList *wins; #endif @@ -197,11 +197,11 @@ /* Clear out the proto data that was freed in the prpl close method*/ buddies = purple_find_buddies(account, NULL); - for (tmp = buddies; tmp; tmp = tmp->next) { - PurpleBuddy *buddy = tmp->data; + while (buddies != NULL) { + PurpleBuddy *buddy = buddies->data; buddy->proto_data = NULL; + buddies = g_slist_delete_link(buddies, buddies); } - g_slist_free(buddies); connections = g_list_remove(connections, gc);
--- a/libpurple/privacy.c Thu May 03 07:51:51 2007 +0000 +++ b/libpurple/privacy.c Thu May 03 07:55:32 2007 +0000 @@ -206,7 +206,8 @@ static void add_buddies_in_permit(PurpleAccount *account, gboolean local) { - GSList *list, *iter; + GSList *list; + /* Remove anyone in the permit list who is not in the buddylist */ for (list = account->permit; list != NULL; ) { char *person = list->data; @@ -214,13 +215,16 @@ if (!purple_find_buddy(account, person)) purple_privacy_permit_remove(account, person, local); } + /* Now make sure everyone in the buddylist is in the permit list */ - for (iter = list = purple_find_buddies(account, NULL); iter; iter = iter->next) { - PurpleBuddy *buddy = iter->data; + list = purple_find_buddies(account, NULL); + while (list != NULL) + { + PurpleBuddy *buddy = list->data; if (!g_slist_find_custom(account->permit, buddy->name, (GCompareFunc)g_utf8_collate)) purple_privacy_permit_add(account, buddy->name, local); + list = g_slist_delete_link(list, list); } - g_slist_free(list); } void
--- a/libpurple/server.c Thu May 03 07:51:51 2007 +0000 +++ b/libpurple/server.c Thu May 03 07:55:32 2007 +0000 @@ -210,22 +210,24 @@ serv_got_alias(PurpleConnection *gc, const char *who, const char *alias) { PurpleAccount *account = purple_connection_get_account(gc); - GSList *buds, *buddies = purple_find_buddies(account, who); + GSList *buddies = purple_find_buddies(account, who); PurpleBuddy *b; PurpleConversation *conv; - for (buds = buddies; buds; buds = buds->next) + while (buddies != NULL) { - b = buds->data; + b = buddies->data; + buddies = g_slist_delete_link(buddies, buddies); + if ((b->server_alias == NULL && alias == NULL) || (b->server_alias && alias && !strcmp(b->server_alias, alias))) { continue; } + purple_blist_server_alias_buddy(b, alias); conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, b->name, account); - if (conv != NULL && alias != NULL && strcmp(alias, who)) { char *tmp = g_strdup_printf(_("%s is now known as %s.\n"), @@ -237,7 +239,6 @@ g_free(tmp); } } - g_slist_free(buddies); } /*