]> Savannah Git Hosting - gnulib.git/commitdiff
exclude: improve wide-character hashing
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 12 Jun 2021 00:18:57 +0000 (17:18 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 12 Jun 2021 00:20:10 +0000 (17:20 -0700)
* lib/exclude.c (string_hasher_ci): Take the modulo at the end
rather than each time a wide character is retrieved; this should
be more efficient and should hash better.

ChangeLog
lib/exclude.c

index d57d006ff59a4c794e0ff6fb77a94c3c068c1ce5..304599f810d075adb6fa40e101157e96a3b6f113 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2021-06-11  Paul Eggert  <eggert@cs.ucla.edu>
+
+       exclude: improve wide-character hashing
+       * lib/exclude.c (string_hasher_ci): Take the modulo at the end
+       rather than each time a wide character is retrieved; this should
+       be more efficient and should hash better.
+
 2021-06-11  Bruno Haible  <bruno@clisp.org>
 
        Make message in last commit more precise.
index 4ef4e08f139e6a996d2063276a2b2dd0a2435ad7..6287fbc6891775f089cc5e84ffa99ac4f0ee0c85 100644 (file)
@@ -219,10 +219,10 @@ string_hasher_ci (void const *data, size_t n_buckets)
       else
         wc = *m.ptr;
 
-      value = (value * 31 + wc) % n_buckets;
+      value = value * 31 + wc;
     }
 
-  return value;
+  return value % n_buckets;
 }
 
 /* compare two strings for equality */