aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsinanmohd <sinan@firemail.cc>2023-05-10 09:42:48 +0530
committersinanmohd <sinan@firemail.cc>2023-05-10 09:42:48 +0530
commit5c032ac33810cc3d01bdcc1cdb12bc8b913a696c (patch)
treef79d22a64905f3973c57c7ed65a8f69b554ddf42
parent73526f53e58c476507c44fd94412b04244ab0930 (diff)
6.5: hash.c: undef v2 rewrite
-rw-r--r--6.5/hash.c33
1 files 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;
}
}