From 5c032ac33810cc3d01bdcc1cdb12bc8b913a696c Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Wed, 10 May 2023 09:42:48 +0530 Subject: 6.5: hash.c: undef v2 rewrite --- 6.5/hash.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/6.5/hash.c b/6.5/hash.c index 1e29bd7..cd9cf73 100644 --- a/6.5/hash.c +++ b/6.5/hash.c @@ -60,21 +60,24 @@ struct nlist *install(struct nlist *hashtab[], uint32_t hashsize, void undef(struct nlist *hashtab[], uint32_t hashsize, char *name) { - struct nlist *cur, *last; - uint32_t hashval = hash(name, hashsize); - - for (cur = hashtab[hashval], last = NULL; cur !=NULL; last = cur, - cur = cur->next) { - if (!strcmp(cur->name, name)) { - if (last == NULL) - hashtab[hashval] = cur->next; - else - last->next = cur->next; - - cur->next = NULL; - nlfree(cur); - return; - } + struct nlist *np, *prev; + uint32_t h; + + prev = NULL; + h = hash(name, hashsize); + for (np = hashtab[h]; np != NULL; prev = np, np = np->next) + if (!strcmp(name, np->name)) + break; + + if (np != NULL) { + if (prev == NULL) + hashtab[h] = np->next; + else + prev->next = np->next; + + np->next = NULL; + nlfree(np); + return; } } -- cgit v1.2.3