]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Speed up generation of Unicode hash functions.
authorJohn Naylor <john.naylor@postgresql.org>
Thu, 12 Aug 2021 13:08:56 +0000 (09:08 -0400)
committerJohn Naylor <john.naylor@postgresql.org>
Thu, 12 Aug 2021 13:08:56 +0000 (09:08 -0400)
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.

src/tools/PerfectHash.pm

index db06d0461c435d070a4cc78a17713cab7e9ef7a5..ce03ed8bbcb3aa522d4f58eb1fa2bad0335e2307 100644 (file)
@@ -87,13 +87,13 @@ sub generate_hash_function
        my $hash_seed2;
        my @subresult;
   FIND_PARAMS:
-       foreach (17, 31, 127, 8191)
+       for ($hash_seed1 = 0; $hash_seed1 < 10; $hash_seed1++)
        {
-               $hash_mult2 = $_;    # "foreach $hash_mult2" doesn't work
-               for ($hash_seed1 = 0; $hash_seed1 < 10; $hash_seed1++)
+               for ($hash_seed2 = 0; $hash_seed2 < 10; $hash_seed2++)
                {
-                       for ($hash_seed2 = 0; $hash_seed2 < 10; $hash_seed2++)
+                       foreach (17, 31, 127, 8191)
                        {
+                               $hash_mult2 = $_;    # "foreach $hash_mult2" doesn't work
                                @subresult = _construct_hash_table(
                                        $keys_ref,   $hash_mult1, $hash_mult2,
                                        $hash_seed1, $hash_seed2);