diff options
author | James Booth <boothj5@gmail.com> | 2015-05-07 00:26:24 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2015-05-07 00:26:24 +0100 |
commit | 6fd9b179a08126deb20d6efedac3089e9bf432cb (patch) | |
tree | cab3185e03473220a39653c10c769f9ea83731ee | |
parent | ca3f7412f58aeb601404417f27dd98e0ffbb2b40 (diff) | |
download | profani-tty-6fd9b179a08126deb20d6efedac3089e9bf432cb.tar.gz |
Optimised occupant comparisons, create utf8 collate key once
-rw-r--r-- | src/muc.c | 15 | ||||
-rw-r--r-- | src/muc.h | 1 |
2 files changed, 7 insertions, 9 deletions
diff --git a/src/muc.c b/src/muc.c index 6fd09de3..d283b55e 100644 --- a/src/muc.c +++ b/src/muc.c @@ -832,16 +832,10 @@ _free_room(ChatRoom *room) static gint _compare_occupants(Occupant *a, Occupant *b) { - const char * utf8_str_a = a->nick; - const char * utf8_str_b = b->nick; + const char * utf8_str_a = a->nick_collate_key; + const char * utf8_str_b = b->nick_collate_key; - gchar *key_a = g_utf8_collate_key(utf8_str_a, -1); - gchar *key_b = g_utf8_collate_key(utf8_str_b, -1); - - gint result = g_strcmp0(key_a, key_b); - - g_free(key_a); - g_free(key_b); + gint result = g_strcmp0(utf8_str_a, utf8_str_b); return result; } @@ -947,8 +941,10 @@ _muc_occupant_new(const char *const nick, const char * const jid, muc_role_t rol if (nick) { occupant->nick = strdup(nick); + occupant->nick_collate_key = g_utf8_collate_key(occupant->nick, -1); } else { occupant->nick = NULL; + occupant->nick_collate_key = NULL; } if (jid) { @@ -976,6 +972,7 @@ _occupant_free(Occupant *occupant) { if (occupant) { free(occupant->nick); + free(occupant->nick_collate_key); free(occupant->jid); free(occupant->status); free(occupant); diff --git a/src/muc.h b/src/muc.h index cdaa10bd..ad96f3d9 100644 --- a/src/muc.h +++ b/src/muc.h @@ -64,6 +64,7 @@ typedef enum { typedef struct _muc_occupant_t { char *nick; + gchar *nick_collate_key; char *jid; muc_role_t role; muc_affiliation_t affiliation; |