bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: bug-gnulib@gnu.org
Cc: Paul Eggert <eggert@cs.ucla.edu>
Subject: [PATCH] exclude: improve wide-character hashing
Date: Fri, 11 Jun 2021 17:20:54 -0700	[thread overview]
Message-ID: <20210612002054.1105452-1-eggert@cs.ucla.edu> (raw)

* 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     | 7 +++++++
 lib/exclude.c | 4 ++--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index d57d006ff..304599f81 100644
--- 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.
diff --git a/lib/exclude.c b/lib/exclude.c
index 4ef4e08f1..6287fbc68 100644
--- a/lib/exclude.c
+++ b/lib/exclude.c
@@ -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 */
-- 
2.30.2



                 reply	other threads:[~2021-06-12  0:21 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210612002054.1105452-1-eggert@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=bug-gnulib@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).