# HG changeset patch # User Matti Hamalainen # Date 1337998211 -10800 # Node ID aeb3171f9e28185c2385f069e5701628656eb425 # Parent 733396469e5d4883473a0da2161a154dbf859223 Simplify the userhash matching code a bit. diff -r 733396469e5d -r aeb3171f9e28 util.c --- 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;