]> git.sesse.net Git - skvidarsync/commitdiff
Add a cache in front of Unicode::Collate.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 11 Nov 2023 13:24:59 +0000 (14:24 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 11 Nov 2023 13:24:59 +0000 (14:24 +0100)
bin/sync.pl

index 7b82cace50b6cd781361a8b2b6a94502ff6121a9..949548b58d76c14f70e703566537d481e891620b 100644 (file)
@@ -52,9 +52,29 @@ sub log_timing {
        printf "%s: %.0f ms.\n", $msg, 1e3 * $elapsed;
 }
 
+# Unicode::Collate is seemingly slow, so add a cache for each name part
+# (which, of course, only works for equality).
+# Doesn't seem to help the initial one, though; I guess not enough people
+# have the same names.
+my %sort_key_cache = ();
+my $sort_key_sp = $uca->getSortKey(' ');
+
 sub sort_key {
        my $m = shift;
-       return $uca->getSortKey($m);
+       my $sk;
+       for my $part (split /\s+/, $m) {
+               my $psk = \$sort_key_cache{$part};
+               if (!defined($$psk)) {
+                       $$psk = $uca->getSortKey($part);
+               }
+               if (defined($sk)) {
+                       $sk .= $sort_key_sp;
+                       $sk .= $$psk;
+               } else {
+                       $sk = $$psk;
+               }
+       }
+       return $sk;
 }
 
 sub get_oauth_bearer_token {