aboutsummaryrefslogtreecommitdiff
path: root/libiberty/hashtab.c
diff options
context:
space:
mode:
authorDJ Delorie <dj@redhat.com>2006-07-27 18:05:31 +0000
committerDJ Delorie <dj@redhat.com>2006-07-27 18:05:31 +0000
commita7d421b8150c07eb5e9be3982f3e6ec2add9800e (patch)
tree301c7a22bfeeeab91749eec6d0eb46de49b36df9 /libiberty/hashtab.c
parent9f2e1e6389f472b35807eddd064b1ba90a2e3ada (diff)
downloadgdb-a7d421b8150c07eb5e9be3982f3e6ec2add9800e.zip
gdb-a7d421b8150c07eb5e9be3982f3e6ec2add9800e.tar.gz
gdb-a7d421b8150c07eb5e9be3982f3e6ec2add9800e.tar.bz2
merge from gcc
Diffstat (limited to 'libiberty/hashtab.c')
-rw-r--r--libiberty/hashtab.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/libiberty/hashtab.c b/libiberty/hashtab.c
index a5671a0..bf34a6d 100644
--- a/libiberty/hashtab.c
+++ b/libiberty/hashtab.c
@@ -421,7 +421,28 @@ htab_empty (htab_t htab)
if (entries[i] != HTAB_EMPTY_ENTRY && entries[i] != HTAB_DELETED_ENTRY)
(*htab->del_f) (entries[i]);
- memset (entries, 0, size * sizeof (PTR));
+ /* Instead of clearing megabyte, downsize the table. */
+ if (size > 1024*1024 / sizeof (PTR))
+ {
+ int nindex = higher_prime_index (1024 / sizeof (PTR));
+ int nsize = prime_tab[nindex].prime;
+
+ if (htab->free_f != NULL)
+ (*htab->free_f) (htab->entries);
+ else if (htab->free_with_arg_f != NULL)
+ (*htab->free_with_arg_f) (htab->alloc_arg, htab->entries);
+ if (htab->alloc_with_arg_f != NULL)
+ htab->entries = (PTR *) (*htab->alloc_with_arg_f) (htab->alloc_arg, nsize,
+ sizeof (PTR *));
+ else
+ htab->entries = (PTR *) (*htab->alloc_f) (nsize, sizeof (PTR *));
+ htab->size = nsize;
+ htab->size_prime_index = nindex;
+ }
+ else
+ memset (entries, 0, size * sizeof (PTR));
+ htab->n_deleted = 0;
+ htab->n_elements = 0;
}
/* Similar to htab_find_slot, but without several unwanted side effects: