]> sjero.net Git - wget/blobdiff - src/hash.c
[svn] Commit my url.c fix (space as unsafe character) and Jan's
[wget] / src / hash.c
index 0749f57bdb58cf35549c310a9078438ba3a3c0df..42159112d110f8a2d589a62d4548080f9bbc368c 100644 (file)
@@ -32,6 +32,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #ifdef STANDALONE
 # define xmalloc malloc
 # define xrealloc realloc
+# define xfree free
 #endif
 
 /* INTERFACE:
@@ -192,8 +193,8 @@ hash_table_new (int initial_size,
 void
 hash_table_destroy (struct hash_table *ht)
 {
-  free (ht->mappings);
-  free (ht);
+  xfree (ht->mappings);
+  xfree (ht);
 }
 
 /* The heart of almost all functions in this file -- find the mapping
@@ -320,7 +321,7 @@ grow_hash_table (struct hash_table *ht)
        hash_table_put (ht, mp_key, mp->value);
     }
   assert (ht->count == old_count);
-  free (old_mappings);
+  xfree (old_mappings);
 }
 
 /* Put VALUE in the hash table HT under the key KEY.  This regrows the
@@ -329,8 +330,8 @@ grow_hash_table (struct hash_table *ht)
 void
 hash_table_put (struct hash_table *ht, const void *key, void *value)
 {
-  /* Cannot use find_mapping here because we treat deleted entries
-     specially.  */
+  /* Cannot use find_mapping here because we're actually looking for
+     an *empty* entry.  */
 
   struct mapping *mappings = ht->mappings;
   int size = ht->size;
@@ -349,24 +350,18 @@ hash_table_put (struct hash_table *ht, const void *key, void *value)
          mp->value = value;
          break;
        }
-      else if (DELETED_ENTRY_P (mp_key))
+      else if (DELETED_ENTRY_P (mp_key)
+              || !ht->test_function (key, mp_key))
        {
-         /* We're replacing a deleteed entry, so ht->count gets
-             increased, but ht->fullness remains unchanged.  */
-         ++ht->count;
-         goto just_insert;
+         if (++location == size)
+           location = 0;
        }
-      else if (ht->test_function (key, mp_key))
+      else                     /* equal to key and not deleted */
        {
          /* We're replacing an existing entry, so ht->count and
              ht->fullness remain unchanged.  */
          goto just_insert;
        }
-      else
-       {
-         if (++location == size)
-           location = 0;
-       }
     }
   if (ht->fullness * 4 > ht->size * 3)
     /* When fullness exceeds 75% of size, regrow the table. */
@@ -550,7 +545,7 @@ main (void)
          if (hash_table_get_pair (ht, line, &line_copy, NULL))
            {
              hash_table_remove (ht, line);
-             free (line_copy);
+             xfree (line_copy);
            }
        }
 #endif