git » nmdb » commit 7a60adf

Simplify find_in_chain() loop

author Alberto Bertogli
2008-07-11 17:26:29 UTC
committer Alberto Bertogli
2008-07-11 17:26:29 UTC
parent fb8da7a63124143a63a77f90c542b888ec2fe507

Simplify find_in_chain() loop

The code fits a for loop perfectly, and it's more clear that way.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>

nmdb/cache.c +3 -11

diff --git a/nmdb/cache.c b/nmdb/cache.c
index 522ac4d..963d6d9 100644
--- a/nmdb/cache.c
+++ b/nmdb/cache.c
@@ -112,27 +112,19 @@ static uint32_t hash(const unsigned char *key, const size_t ksize)
 static struct cache_entry *find_in_chain(struct cache_chain *c,
 		const unsigned char *key, size_t ksize)
 {
-	int found = 0;
 	struct cache_entry *e;
 
-	e = c->first;
-	while (e != NULL) {
+	for (e = c->first; e != NULL; e = e->next) {
 		if (ksize != e->ksize) {
-			e = e->next;
 			continue;
 		}
 		if (memcmp(key, e->key, ksize) == 0) {
-			found = 1;
 			break;
 		}
-
-		e = e->next;
 	}
 
-	if (found)
-		return e;
-	return NULL;
-
+	/* e will be either the found chain or NULL */
+	return e;
 }
 
 /* Gets the matching value for the given key.  Returns 0 if no match was