changeset 452:aeb3171f9e28

Simplify the userhash matching code a bit.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 26 May 2012 05:10:11 +0300
parents 733396469e5d
children d55cc0b73c62
files util.c
diffstat 1 files changed, 15 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/util.c	Sat May 26 05:09:49 2012 +0300
+++ b/util.c	Sat May 26 05:10:11 2012 +0300
@@ -501,13 +501,11 @@
 
 static nn_user_t *nn_userhash_match_do(nn_user_t *list, const char *pattern, size_t len)
 {
-    nn_user_t *curr = list;
-
-    while (curr != NULL)
+    nn_user_t *node;
+    for (node = list; node != NULL; node = node->next)
     {
-        if (len <= strlen(curr->name) && th_strncasecmp(curr->name, pattern, len) == 0)
-            return curr;
-        curr = curr->next;
+        if (len <= strlen(node->name) && th_strncasecmp(node->name, pattern, len) == 0)
+            return node;
     }
     return NULL;
 }
@@ -522,30 +520,28 @@
     hash = nn_hash_user(pattern);
     if (list->buckets[hash] != NULL)
     {
-        nn_user_t *curr = list->buckets[hash];
+        nn_user_t *node;
         size_t len = strlen(pattern);
 
         if (current != NULL)
         {
-            nn_user_t *found = NULL;
-            while (curr != NULL)
+            for (node = list->buckets[hash]; node != NULL; node = node->next)
             {
-                if (th_strcasecmp(curr->name, current) == 0)
+                if (th_strcasecmp(node->name, current) == 0)
                 {
+                    nn_user_t *found;
+
                     if (again)
-                        return curr;
-                    found = curr->next;
-                    break;
+                        return node;
+
+                    if ((found = nn_userhash_match_do(node->next, pattern, len)) != NULL)
+                        return found;
                 }
-                curr = curr->next;
             }
-
-            if (found != NULL && (found = nn_userhash_match_do(found, pattern, len)) != NULL)
-                return found;
         }
 
-        if ((curr = nn_userhash_match_do(list->buckets[hash], pattern, len)) != NULL)
-            return curr;
+        if ((node = nn_userhash_match_do(list->buckets[hash], pattern, len)) != NULL)
+            return node;
     }
 
     return NULL;