pidgin: 56b164b2: It's wrong, unnecessary, and expensive t...

markdoliner at pidgin.im markdoliner at pidgin.im
Mon Feb 9 20:45:39 EST 2009


-----------------------------------------------------------------
Revision: 56b164b2043c3890f5e81b3517f6f2ebd3061fb9
Ancestor: 2c144d518c5cab8f06dc3158247517eec0c23b69
Author: markdoliner at pidgin.im
Date: 2009-02-10T01:44:40
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/56b164b2043c3890f5e81b3517f6f2ebd3061fb9

Modified files:
        libpurple/privacy.c

ChangeLog: 

It's wrong, unnecessary, and expensive to use purple_utf8_strcasecmp() here.
1. Wrong because we shouldn't presume to know how the prpl wants their
   usernames compared
2. Unnecessary because we're already comparing two normalized names
   (everything in PurpleAccount->permit and PurpleAccount->deny) should
   be normalized
3. Expensive because MSN calls these functions a lot, and g_utf8_collate
   and g_utf8_casefold are both pretty expensive

-------------- next part --------------
============================================================
--- libpurple/privacy.c	aaccb228db3b3a76dda13d1ac48beed6a3f4ef91
+++ libpurple/privacy.c	6047db826ce191f145eae3e688c53649dc6fdefa
@@ -42,12 +42,14 @@ purple_privacy_permit_add(PurpleAccount 
 	name = g_strdup(purple_normalize(account, who));
 
 	for (l = account->permit; l != NULL; l = l->next) {
-		if (!purple_utf8_strcasecmp(name, (char *)l->data))
+		if (g_str_equal(name, l->data))
+			/* This buddy already exists */
 			break;
 	}
 
 	if (l != NULL)
 	{
+		/* This buddy already exists, so bail out */
 		g_free(name);
 		return FALSE;
 	}
@@ -86,11 +88,13 @@ purple_privacy_permit_remove(PurpleAccou
 	name = purple_normalize(account, who);
 
 	for (l = account->permit; l != NULL; l = l->next) {
-		if (!purple_utf8_strcasecmp(name, (char *)l->data))
+		if (g_str_equal(name, l->data))
+			/* We found the buddy we were looking for */
 			break;
 	}
 
 	if (l == NULL)
+		/* We didn't find the buddy we were looking for, so bail out */
 		return FALSE;
 
 	/* We should not free l->data just yet. There can be occasions where
@@ -130,12 +134,14 @@ purple_privacy_deny_add(PurpleAccount *a
 	name = g_strdup(purple_normalize(account, who));
 
 	for (l = account->deny; l != NULL; l = l->next) {
-		if (!purple_utf8_strcasecmp(name, purple_normalize(account, (char *)l->data)))
+		if (g_str_equal(name, l->data))
+			/* This buddy already exists */
 			break;
 	}
 
 	if (l != NULL)
 	{
+		/* This buddy already exists, so bail out */
 		g_free(name);
 		return FALSE;
 	}
@@ -173,15 +179,17 @@ purple_privacy_deny_remove(PurpleAccount
 	normalized = purple_normalize(account, who);
 
 	for (l = account->deny; l != NULL; l = l->next) {
-		if (!purple_utf8_strcasecmp(normalized, (char *)l->data))
+		if (g_str_equal(normalized, l->data))
+			/* We found the buddy we were looking for */
 			break;
 	}
 
-	buddy = purple_find_buddy(account, normalized);
-
 	if (l == NULL)
+		/* We didn't find the buddy we were looking for, so bail out */
 		return FALSE;
 
+	buddy = purple_find_buddy(account, normalized);
+
 	name = l->data;
 	account->deny = g_slist_delete_link(account->deny, l);
 


More information about the Commits mailing list