From 0194e877a39d909dfcc6db2057be773c6a01f7d2 Mon Sep 17 00:00:00 2001 From: Zack Weinberg Date: Wed, 29 Mar 2000 19:04:54 +0000 Subject: hashtab.c (htab_find_with_hash): Avoid calculating hash2 unless it will be used. * hashtab.c (htab_find_with_hash): Avoid calculating hash2 unless it will be used. Rearrange loop for better optimization. (higher_prime_number): Add static prototype. From-SVN: r32809 --- libiberty/hashtab.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'libiberty/hashtab.c') diff --git a/libiberty/hashtab.c b/libiberty/hashtab.c index 16c5d3e..027f75d 100644 --- a/libiberty/hashtab.c +++ b/libiberty/hashtab.c @@ -55,8 +55,10 @@ Boston, MA 02111-1307, USA. */ #define DELETED_ENTRY ((void *) 1) +static unsigned long higher_prime_number PARAMS ((unsigned long)); + /* The following function returns the nearest prime number which is - greater than given source number. */ + greater than a given source number. */ static unsigned long higher_prime_number (n) @@ -223,24 +225,30 @@ htab_find_with_hash (htab, element, hash) { unsigned int index, hash2; size_t size; + void *entry; htab->searches++; size = htab->size; - hash2 = 1 + hash % (size - 2); index = hash % size; + entry = htab->entries[index]; + if (entry == EMPTY_ENTRY + || (entry != DELETED_ENTRY && (*htab->eq_f) (entry, element))) + return entry; + + hash2 = 1 + hash % (size - 2); + for (;;) { - void *entry = htab->entries[index]; - if (entry == EMPTY_ENTRY) - return NULL; - else if (entry != DELETED_ENTRY && (*htab->eq_f) (entry, element)) - return entry; - htab->collisions++; index += hash2; if (index >= size) index -= size; + + entry = htab->entries[index]; + if (entry == EMPTY_ENTRY + || (entry != DELETED_ENTRY && (*htab->eq_f) (entry, element))) + return entry; } } -- cgit v1.1