# HG changeset patch # User Mark Doliner # Date 1234230280 0 # Node ID 8615b929e140ea3c82edd5a9d35fedd49414bae7 # Parent 5fd2102643d56083dd7ded6ed77e7d36bd1ad9ae 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 diff -r 5fd2102643d5 -r 8615b929e140 libpurple/privacy.c --- a/libpurple/privacy.c Mon Feb 09 22:05:14 2009 +0000 +++ b/libpurple/privacy.c Tue Feb 10 01:44:40 2009 +0000 @@ -42,12 +42,14 @@ 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 @@ 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 @@ 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,14 +179,16 @@ 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; - if (l == NULL) - return FALSE; + buddy = purple_find_buddy(account, normalized); name = l->data; account->deny = g_slist_delete_link(account->deny, l);