1
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-02-02 15:08:15 -05:00

Optimised occupant comparisons, create utf8 collate key once

This commit is contained in:
James Booth 2015-05-07 00:26:24 +01:00
parent ca3f7412f5
commit 6fd9b179a0
2 changed files with 7 additions and 9 deletions

View File

@ -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);

View File

@ -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;