mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-29 05:16:21 +00:00
Optimised occupant comparisons, create utf8 collate key once
This commit is contained in:
15
src/muc.c
15
src/muc.c
@@ -832,16 +832,10 @@ _free_room(ChatRoom *room)
|
|||||||
static
|
static
|
||||||
gint _compare_occupants(Occupant *a, Occupant *b)
|
gint _compare_occupants(Occupant *a, Occupant *b)
|
||||||
{
|
{
|
||||||
const char * utf8_str_a = a->nick;
|
const char * utf8_str_a = a->nick_collate_key;
|
||||||
const char * utf8_str_b = b->nick;
|
const char * utf8_str_b = b->nick_collate_key;
|
||||||
|
|
||||||
gchar *key_a = g_utf8_collate_key(utf8_str_a, -1);
|
gint result = g_strcmp0(utf8_str_a, utf8_str_b);
|
||||||
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);
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -947,8 +941,10 @@ _muc_occupant_new(const char *const nick, const char * const jid, muc_role_t rol
|
|||||||
|
|
||||||
if (nick) {
|
if (nick) {
|
||||||
occupant->nick = strdup(nick);
|
occupant->nick = strdup(nick);
|
||||||
|
occupant->nick_collate_key = g_utf8_collate_key(occupant->nick, -1);
|
||||||
} else {
|
} else {
|
||||||
occupant->nick = NULL;
|
occupant->nick = NULL;
|
||||||
|
occupant->nick_collate_key = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (jid) {
|
if (jid) {
|
||||||
@@ -976,6 +972,7 @@ _occupant_free(Occupant *occupant)
|
|||||||
{
|
{
|
||||||
if (occupant) {
|
if (occupant) {
|
||||||
free(occupant->nick);
|
free(occupant->nick);
|
||||||
|
free(occupant->nick_collate_key);
|
||||||
free(occupant->jid);
|
free(occupant->jid);
|
||||||
free(occupant->status);
|
free(occupant->status);
|
||||||
free(occupant);
|
free(occupant);
|
||||||
|
|||||||
Reference in New Issue
Block a user