summaryrefslogtreecommitdiff
path: root/libiberty/hashtab.c
diff options
context:
space:
mode:
authorJan Hubicka <jh@suse.cz>2003-03-12 15:15:09 +0100
committerJan Hubicka <hubicka@gcc.gnu.org>2003-03-12 14:15:09 +0000
commit0a8e3de3c825de0edac26dc0875e823b1b9d6e9b (patch)
tree185c9ce9c769ea7a3f9729796fff47cc59493df1 /libiberty/hashtab.c
parent32cf27e58ed0e95c54c2c2f29ed8130df55f843f (diff)
hashtab.c (htab_expand): Compute the size of hashtable based on the number of elements actually used.
* 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
Diffstat (limited to 'libiberty/hashtab.c')
-rw-r--r--libiberty/hashtab.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/libiberty/hashtab.c b/libiberty/hashtab.c
index 0429936e961..a0cb5a75820 100644
--- a/libiberty/hashtab.c
+++ b/libiberty/hashtab.c
@@ -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
{