adium: ec7b74f8: Add a collate key to PurpleConvChatBuddy...

zacw at adiumx.com zacw at adiumx.com
Tue Apr 14 21:10:41 EDT 2009


-----------------------------------------------------------------
Revision: ec7b74f84bcc99f27c6008c48cf322aaf0a7e12e
Ancestor: d93b477da5818c974015593be1087ea7794baac2
Author: zacw at adiumx.com
Date: 2009-04-15T01:09:34
Branch: im.pidgin.adium
URL: http://d.pidgin.im/viewmtn/revision/info/ec7b74f84bcc99f27c6008c48cf322aaf0a7e12e

Modified files:
        libpurple/conversation.c libpurple/conversation.h

ChangeLog: 

Add a collate key to PurpleConvChatBuddy, and use the key when searching for a specific buddy. This is a *significant* speed increase when searching for a lot of buddies.

-------------- next part --------------
============================================================
--- libpurple/conversation.c	9ce93418a9d470fa78390a05c1a10afe1e770c2b
+++ libpurple/conversation.c	13f5debf179e0e08e7b84f33d90e23ecd034a83b
@@ -2082,6 +2082,7 @@ purple_conv_chat_cb_new(const char *name
 
 	cb = g_new0(PurpleConvChatBuddy, 1);
 	cb->name = g_strdup(name);
+	cb->collate_key = g_utf8_collate_key(name, -1);
 	cb->flags = flags;
 	cb->alias = g_strdup(alias);
 	cb->attributes = g_hash_table_new_full(g_str_hash, g_str_equal,
@@ -2096,15 +2097,22 @@ purple_conv_chat_cb_find(PurpleConvChat 
 {
 	GList *l;
 	PurpleConvChatBuddy *cb = NULL;
+	char *collate_key;
 
 	g_return_val_if_fail(chat != NULL, NULL);
 	g_return_val_if_fail(name != NULL, NULL);
+	
+	collate_key = g_utf8_collate_key(name, -1);
 
 	for (l = purple_conv_chat_get_users(chat); l; l = l->next) {
 		cb = l->data;
-		if (!g_utf8_collate(cb->name, name))
+		if (purple_strequal(cb->collate_key, collate_key)) {
+			g_free(collate_key);
 			return cb;
+		}
 	}
+	
+	g_free(collate_key);
 
 	return NULL;
 }
@@ -2118,6 +2126,7 @@ purple_conv_chat_cb_destroy(PurpleConvCh
 	g_free(cb->alias);
 	g_free(cb->alias_key);
 	g_free(cb->name);
+	g_free(cb->collate_key);
 	g_hash_table_destroy(cb->attributes);
 
 	PURPLE_DBUS_UNREGISTER_POINTER(cb);
============================================================
--- libpurple/conversation.h	4410bcb069d6132e5deeae97a2b99c61b191bdee
+++ libpurple/conversation.h	dfbdf0b44384e7c78f931a45df73ea49f8b8ae0d
@@ -286,6 +286,7 @@ struct _PurpleConvChatBuddy
 struct _PurpleConvChatBuddy
 {
 	char *name;                      /**< The chat participant's name in the chat. */
+	char *collate_key;				 /**< A string by which this buddy can be compared with other collate keys. */
 	char *alias;                     /**< The chat participant's alias, if known;
 	                                  *   @a NULL otherwise.
 	                                  */


More information about the Commits mailing list