]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
hashtab.c (htab_expand): Compute the size of hashtable based on the number of element...
authorJan Hubicka <jh@suse.cz>
Wed, 12 Mar 2003 14:15:09 +0000 (15:15 +0100)
committerJan Hubicka <hubicka@gcc.gnu.org>
Wed, 12 Mar 2003 14:15:09 +0000 (14:15 +0000)
* hashtab.c (htab_expand): Compute the size of hashtable based
on the number of elements actually used.
(htab_traverse):  Call htab_expand when table is too empty.

From-SVN: r64246

libiberty/ChangeLog
libiberty/hashtab.c

index c863114f0beb9af50ed2aa860868bcda2dc6b1f8..16d0b98e123a637793ae15c3b8f9eb5d70e14934 100644 (file)
@@ -1,3 +1,9 @@
+2003-12-03  Jan Hubicka  <jh@suse.cz>
+
+       * hashtab.c (htab_expand): Compute the size of hashtable based
+       on the number of elements actually used.
+       (htab_traverse):  Call htab_expand when table is too empty.
+
 2003-03-11  Carlo Wood  <carlo@gnu.org>
 
        * cplus-dem.c (demangle_integral_value): Correction to reflect
index 0429936e96146f60486f8c1fc73faaea150b4b94..a0cb5a75820b559b1f50bf19070cd97bf4f21803 100644 (file)
@@ -373,7 +373,14 @@ htab_expand (htab)
   oentries = htab->entries;
   olimit = oentries + htab->size;
 
-  nsize = higher_prime_number (htab->size * 2);
+  /* Resize only when table after removal of unused elements is either
+     too full or too empty.  */
+  if ((htab->n_elements - htab->n_deleted) * 2 > htab->size
+      || (htab->n_elements - htab->n_deleted) * 8 < htab->size
+    && htab->size > 32)
+    nsize = higher_prime_number ((htab->n_elements - htab->n_deleted) * 2);
+  else
+    nsize = htab->size;
 
   if (htab->alloc_with_arg_f != NULL)
     nentries = (PTR *) (*htab->alloc_with_arg_f) (htab->alloc_arg, nsize,
@@ -601,8 +608,14 @@ htab_traverse (htab, callback, info)
      htab_trav callback;
      PTR info;
 {
-  PTR *slot = htab->entries;
-  PTR *limit = slot + htab->size;
+  PTR *slot;
+  PTR *limit;
+
+  if ((htab->n_elements - htab->n_deleted) * 8 < htab->size)
+    htab_expand (htab);
+
+  slot = htab->entries;
+  limit = slot + htab->size;
 
   do
     {