From 3de226624354e4f73db48bf6238835059d6f88fd Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 23 Jan 2016 10:35:40 -0500 Subject: [PATCH] ircd: monitor: use irc_radixtree instead of home-grown hashtable --- ircd/monitor.c | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/ircd/monitor.c b/ircd/monitor.c index 25df1793..1c1aa77d 100644 --- a/ircd/monitor.c +++ b/ircd/monitor.c @@ -37,44 +37,31 @@ #include "hash.h" #include "numeric.h" #include "send.h" +#include "irc_radixtree.h" -static rb_dlink_list monitorTable[MONITOR_HASH_SIZE]; -static rb_bh *monitor_heap; +static struct irc_radixtree *monitor_tree; void init_monitor(void) { - monitor_heap = rb_bh_create(sizeof(struct monitor), MONITOR_HEAP_SIZE, "monitor_heap"); -} - -static inline unsigned int -hash_monitor_nick(const char *name) -{ - return fnv_hash_upper((const unsigned char *)name, MONITOR_HASH_BITS); + monitor_tree = irc_radixtree_create("monitor lists", irc_radixtree_irccasecanon); } struct monitor * find_monitor(const char *name, int add) { struct monitor *monptr; - rb_dlink_node *ptr; - unsigned int hashv = hash_monitor_nick(name); - - RB_DLINK_FOREACH(ptr, monitorTable[hashv].head) - { - monptr = ptr->data; - if(!irccmp(monptr->name, name)) - return monptr; - } + monptr = irc_radixtree_retrieve(monitor_tree, name); + if (monptr != NULL) + return monptr; if(add) { - monptr = rb_bh_alloc(monitor_heap); + monptr = rb_malloc(sizeof(*monptr)); rb_strlcpy(monptr->name, name, sizeof(monptr->name)); - monptr->hashv = hashv; + irc_radixtree_add(monitor_tree, monptr->name, monptr); - rb_dlinkAdd(monptr, &monptr->node, &monitorTable[hashv]); return monptr; } @@ -87,8 +74,8 @@ free_monitor(struct monitor *monptr) if (rb_dlink_list_length(&monptr->users) > 0) return; - rb_dlinkDelete(&monptr->node, &monitorTable[monptr->hashv]); - rb_bh_free(monitor_heap, monptr); + irc_radixtree_delete(monitor_tree, monptr->name); + rb_free(monptr); } /* monitor_signon()