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
This commit is contained in:
parent
c6b5cb4604
commit
0194e877a3
|
@ -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)
|
Thu Mar 16 01:33:58 2000 Jeffrey A Law (law@cygnus.com)
|
||||||
|
|
||||||
* Makefile.in (partition.o): Depend on config.h
|
* Makefile.in (partition.o): Depend on config.h
|
||||||
|
|
|
@ -55,8 +55,10 @@ Boston, MA 02111-1307, USA. */
|
||||||
|
|
||||||
#define DELETED_ENTRY ((void *) 1)
|
#define DELETED_ENTRY ((void *) 1)
|
||||||
|
|
||||||
|
static unsigned long higher_prime_number PARAMS ((unsigned long));
|
||||||
|
|
||||||
/* The following function returns the nearest prime number which is
|
/* The following function returns the nearest prime number which is
|
||||||
greater than given source number. */
|
greater than a given source number. */
|
||||||
|
|
||||||
static unsigned long
|
static unsigned long
|
||||||
higher_prime_number (n)
|
higher_prime_number (n)
|
||||||
|
@ -223,24 +225,30 @@ htab_find_with_hash (htab, element, hash)
|
||||||
{
|
{
|
||||||
unsigned int index, hash2;
|
unsigned int index, hash2;
|
||||||
size_t size;
|
size_t size;
|
||||||
|
void *entry;
|
||||||
|
|
||||||
htab->searches++;
|
htab->searches++;
|
||||||
size = htab->size;
|
size = htab->size;
|
||||||
hash2 = 1 + hash % (size - 2);
|
|
||||||
index = hash % size;
|
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 (;;)
|
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++;
|
htab->collisions++;
|
||||||
index += hash2;
|
index += hash2;
|
||||||
if (index >= size)
|
if (index >= size)
|
||||||
index -= size;
|
index -= size;
|
||||||
|
|
||||||
|
entry = htab->entries[index];
|
||||||
|
if (entry == EMPTY_ENTRY
|
||||||
|
|| (entry != DELETED_ENTRY && (*htab->eq_f) (entry, element)))
|
||||||
|
return entry;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue