X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=lib-lib%2Fhash.c;h=eea6cd6e1da5ef259ac13bd1605d5d28ace711d1;hp=61e2e4ffcb46eadc49443b86ca63a084f8997350;hb=06972cc96259a466cf14821d8b803bf3972d8fa2;hpb=3e611c4b53a33408955152e1c9336f8643ea096e diff --git a/lib-lib/hash.c b/lib-lib/hash.c index 61e2e4f..eea6cd6 100644 --- a/lib-lib/hash.c +++ b/lib-lib/hash.c @@ -22,13 +22,7 @@ * Copyright (C) 1996-2000 Michael R. Elkins */ -#include -#include -#include - -#include "mem.h" -#include "str.h" -#include "hash.h" +#include "lib-lib.h" #define SOMEPRIME 149711 @@ -100,11 +94,11 @@ int hash_insert(HASH *table, const char *key, void *data, int allow_dup) table->table[h] = ptr; table->curnelem++; } else { - struct hash_elem *tmp, *last; - int r; + struct hash_elem **e; + + for (e = &table->table[h]; *e; e = &(*e)->next) { + int r = m_strcmp((*e)->key, key); - for (tmp = table->table[h], last = NULL; tmp; last = tmp, tmp = tmp->next) { - r = m_strcmp(tmp->key, key); if (r == 0) { p_delete(&ptr); return (-1); @@ -112,12 +106,8 @@ int hash_insert(HASH *table, const char *key, void *data, int allow_dup) if (r > 0) break; } - if (last) { - last->next = ptr; - } else { - table->table[h] = ptr; - } - ptr->next = tmp; + ptr->next = *e; + *e = ptr; table->curnelem++; } return h;