summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorailin-nemui <ailin-nemui@users.noreply.github.com>2017-05-14 09:40:55 +0200
committerGitHub <noreply@github.com>2017-05-14 09:40:55 +0200
commit476f19f1235d7d28ede002be3c7a249952124058 (patch)
tree46debfd5fbd24669bb13bdaaf70b3870776c0182 /src
parent689e80c087669aa19915fd0160f6f9f1eb7e21a5 (diff)
parent371eb7f5052b9cce7efcbcc4086cd6f6716e21fd (diff)
downloadirssi-476f19f1235d7d28ede002be3c7a249952124058.zip
Merge pull request #705 from ailin-nemui/nicklist-performance
improve nicklist performance
Diffstat (limited to 'src')
-rw-r--r--src/core/nicklist.c46
1 files changed, 24 insertions, 22 deletions
diff --git a/src/core/nicklist.c b/src/core/nicklist.c
index 770b0afc..54dfb5fb 100644
--- a/src/core/nicklist.c
+++ b/src/core/nicklist.c
@@ -169,37 +169,39 @@ void nicklist_rename_unique(SERVER_REC *server,
static NICK_REC *nicklist_find_wildcards(CHANNEL_REC *channel,
const char *mask)
{
- GSList *nicks, *tmp;
NICK_REC *nick;
-
- nicks = nicklist_getnicks(channel);
- nick = NULL;
- for (tmp = nicks; tmp != NULL; tmp = tmp->next) {
- nick = tmp->data;
-
- if (mask_match_address(channel->server, mask,
- nick->nick, nick->host))
- break;
+ GHashTableIter iter;
+
+ g_hash_table_iter_init(&iter, channel->nicks);
+ while (g_hash_table_iter_next(&iter, NULL, (void*)&nick)) {
+ for (; nick != NULL; nick = nick->next) {
+ if (mask_match_address(channel->server, mask,
+ nick->nick, nick->host))
+ return nick;
+ }
}
- g_slist_free(nicks);
- return tmp == NULL ? NULL : nick;
+
+ return NULL;
}
GSList *nicklist_find_multiple(CHANNEL_REC *channel, const char *mask)
{
- GSList *nicks, *tmp, *next;
+ GSList *nicks;
+ NICK_REC *nick;
+ GHashTableIter iter;
g_return_val_if_fail(IS_CHANNEL(channel), NULL);
g_return_val_if_fail(mask != NULL, NULL);
- nicks = nicklist_getnicks(channel);
- for (tmp = nicks; tmp != NULL; tmp = next) {
- NICK_REC *nick = tmp->data;
+ nicks = NULL;
- next = tmp->next;
- if (!mask_match_address(channel->server, mask,
- nick->nick, nick->host))
- nicks = g_slist_remove(nicks, tmp->data);
+ g_hash_table_iter_init(&iter, channel->nicks);
+ while (g_hash_table_iter_next(&iter, NULL, (void*)&nick)) {
+ for (; nick != NULL; nick = nick->next) {
+ if (mask_match_address(channel->server, mask,
+ nick->nick, nick->host))
+ nicks = g_slist_prepend(nicks, nick);
+ }
}
return nicks;
@@ -264,8 +266,8 @@ NICK_REC *nicklist_find_mask(CHANNEL_REC *channel, const char *mask)
static void get_nicks_hash(gpointer key, NICK_REC *rec, GSList **list)
{
while (rec != NULL) {
- *list = g_slist_append(*list, rec);
- rec = rec->next;
+ *list = g_slist_prepend(*list, rec);
+ rec = rec->next;
}
}