Skip to content

Commit ba95829

Browse files
committed
Speed up generation of Unicode hash functions.
Sets of Unicode keys are picky about the primes used when generating a perfect hash function for them. Callers can spend many seconds iterating through all the possible combinations of candidate multipliers and seeds to find one that works. Unicode updates typically happen only once a year, but it still makes development and testing of Unicode scripts unnecessarily slow. To fix, iterate over the primes in the innermost loop. This does not change any existing functions checked into the tree.
1 parent b05f7ec commit ba95829

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/tools/PerfectHash.pm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ sub generate_hash_function
8787
my $hash_seed2;
8888
my @subresult;
8989
FIND_PARAMS:
90-
foreach (17, 31, 127, 8191)
90+
for ($hash_seed1 = 0; $hash_seed1 < 10; $hash_seed1++)
9191
{
92-
$hash_mult2 = $_; # "foreach $hash_mult2" doesn't work
93-
for ($hash_seed1 = 0; $hash_seed1 < 10; $hash_seed1++)
92+
for ($hash_seed2 = 0; $hash_seed2 < 10; $hash_seed2++)
9493
{
95-
for ($hash_seed2 = 0; $hash_seed2 < 10; $hash_seed2++)
94+
foreach (17, 31, 127, 8191)
9695
{
96+
$hash_mult2 = $_; # "foreach $hash_mult2" doesn't work
9797
@subresult = _construct_hash_table(
9898
$keys_ref, $hash_mult1, $hash_mult2,
9999
$hash_seed1, $hash_seed2);

0 commit comments

Comments
 (0)