changeset 23963:d1797f30960f

An optimization for purple_accounts_find() to eliminate a malloc/free per iteration from Florian Queze. Fixes #6194.
author Daniel Atallah <daniel.atallah@gmail.com>
date Sun, 31 Aug 2008 17:54:21 +0000
parents 78c64f7c598f
children 1568dc7a14f8
files COPYRIGHT libpurple/account.c
diffstat 2 files changed, 6 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/COPYRIGHT	Sun Aug 31 17:29:40 2008 +0000
+++ b/COPYRIGHT	Sun Aug 31 17:54:21 2008 +0000
@@ -320,6 +320,7 @@
 Jory A. Pratt
 Brent Priddy
 Justin Pryzby
+Florian Quèze
 Ignacio Casal Quinteiro
 Federicco Mena Quintero
 Yosef Radchenko
--- a/libpurple/account.c	Sun Aug 31 17:29:40 2008 +0000
+++ b/libpurple/account.c	Sun Aug 31 17:54:21 2008 +0000
@@ -2614,18 +2614,18 @@
 
 	for (l = purple_accounts_get_all(); l != NULL; l = l->next) {
 		account = (PurpleAccount *)l->data;
+		if (protocol_id && strcmp(account->protocol_id, protocol_id))
+		  continue;
 
 		who = g_strdup(purple_normalize(account, name));
-		if (!strcmp(purple_normalize(account, purple_account_get_username(account)), who) &&
-			(!protocol_id || !strcmp(account->protocol_id, protocol_id))) {
+		if (!strcmp(purple_normalize(account, purple_account_get_username(account)), who)) {
 			g_free(who);
-			break;
+			return account;
 		}
 		g_free(who);
-		account = NULL;
 	}
 
-	return account;
+	return NULL;
 }
 
 void