diff options
-rw-r--r-- | 6.5/hash.c | 33 |
1 files changed, 18 insertions, 15 deletions
@@ -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; } } |