use some lists for score_t.
[apps/madmutt.git] / lib-lib / hash.c
index 5520389..eea6cd6 100644 (file)
@@ -94,11 +94,11 @@ int hash_insert(HASH *table, const char *key, void *data, int allow_dup)
         table->table[h] = ptr;
         table->curnelem++;
     } else {
         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);
             if (r == 0) {
                 p_delete(&ptr);
                 return (-1);
@@ -106,12 +106,8 @@ int hash_insert(HASH *table, const char *key, void *data, int allow_dup)
             if (r > 0)
                 break;
         }
             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;
         table->curnelem++;
     }
     return h;