summaryrefslogtreecommitdiff
path: root/libiberty
diff options
context:
space:
mode:
authorzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>2000-03-29 19:04:54 +0000
committerzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>2000-03-29 19:04:54 +0000
commit07c797e3355013801ae5e6b369bd714420ca1616 (patch)
tree247bd51960c392c1e23b694da85800874dffe326 /libiberty
parent9b423a5e8726dd8fbb19bab3042f7a6043a79577 (diff)
downloadgcc-07c797e3355013801ae5e6b369bd714420ca1616.tar.gz
* 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@32809 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libiberty')
-rw-r--r--libiberty/ChangeLog7
-rw-r--r--libiberty/hashtab.c24
2 files changed, 23 insertions, 8 deletions
diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog
index c858409d301..42231a35b8f 100644
--- a/libiberty/ChangeLog
+++ b/libiberty/ChangeLog
@@ -1,3 +1,10 @@
+2000-03-29 Zack Weinberg <zack@wolery.cumb.org>
+
+ * 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.
+
Thu Mar 16 01:33:58 2000 Jeffrey A Law (law@cygnus.com)
* Makefile.in (partition.o): Depend on config.h
diff --git a/libiberty/hashtab.c b/libiberty/hashtab.c
index 16c5d3e4b12..027f75d12ac 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;
}
}