From 7c3156bb511b6b84413eead1ffd99bd818bb9b71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B8=D0=BB=D1=8F=D0=BD=20=D0=9F=D0=B0=D0=BB=D0=B0?= =?UTF-8?q?=D1=83=D0=B7=D0=BE=D0=B2?= Date: Tue, 29 Sep 2020 22:15:18 +0300 Subject: [PATCH] hash.c:hash_del: deduplicate code --- lib/hash.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/hash.c b/lib/hash.c index ba1d4b132c..cf85d9d2ca 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -188,7 +188,6 @@ void *hash_lookup(const char *key, hash_table *table) void *hash_del(char *key, hash_table *table) { unsigned val = strhash(key) % table->size; - void *data; bucket *ptr, *last = NULL; if (!(table->table)[val]) @@ -209,15 +208,10 @@ void *hash_del(char *key, hash_table *table) int cmpresult = strcmp(key, ptr->key); if (!cmpresult) { + void *data = ptr->data; if (last != NULL ) { - data = ptr -> data; last -> next = ptr -> next; - if(!table->pool) { - free(ptr->key); - free(ptr); - } - return data; } /* @@ -230,15 +224,15 @@ void *hash_del(char *key, hash_table *table) else { - data = ptr->data; (table->table)[val] = ptr->next; + } if(!table->pool) { free(ptr->key); free(ptr); } return data; } - } else if (cmpresult < 0) { + if (cmpresult < 0) { /* its not here! */ return NULL; }