]> code.delx.au - gnu-emacs/commitdiff
* lread.c (hash_string): Use size_t, not int, for hash computation.
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 28 Apr 2011 05:15:35 +0000 (22:15 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 28 Apr 2011 05:15:35 +0000 (22:15 -0700)
Normally we prefer signed values; but hashing is special, because
it's better to use unsigned division on hash table sizes so that
the remainder is nonnegative.  Also, size_t is the natural width
for hashing into memory.  The previous code used 'int', which doesn't
retain enough info to hash well into very large tables.
(oblookup, oblookup_last_bucket_number, Funintern): Likewise.

src/ChangeLog
src/lread.c

index 52b7f323cd3181ccdc74841b0be079839fac84e9..2bda5ffa46f88d6283b50b9c4881ef3e4d948d09 100644 (file)
@@ -1,5 +1,13 @@
 2011-04-28  Paul Eggert  <eggert@cs.ucla.edu>
 
+       * lread.c (hash_string): Use size_t, not int, for hash computation.
+       Normally we prefer signed values; but hashing is special, because
+       it's better to use unsigned division on hash table sizes so that
+       the remainder is nonnegative.  Also, size_t is the natural width
+       for hashing into memory.  The previous code used 'int', which doesn't
+       retain enough info to hash well into very large tables.
+       (oblookup, oblookup_last_bucket_number, Funintern): Likewise.
+
        * dbusbind.c: Don't possibly lose pointer info when converting.
        (xd_remove_watch, Fdbus_init_bus, xd_read_queued_messages):
        Use XPNTR rather than XHASH, so that the high-order bits of
index 7ffc98b254fe07ca667fd0f561a0f2db3a83e80e..2c8c3acd56a4667d79ed34250df460a7ee12eb4c 100644 (file)
@@ -3611,9 +3611,9 @@ static Lisp_Object initial_obarray;
 
 /* oblookup stores the bucket number here, for the sake of Funintern.  */
 
-static int oblookup_last_bucket_number;
+static size_t oblookup_last_bucket_number;
 
-static int hash_string (const char *ptr, int len);
+static size_t hash_string (const char *ptr, size_t len);
 
 /* Get an error if OBARRAY is not an obarray.
    If it is one, return it.  */
@@ -3755,7 +3755,7 @@ OBARRAY defaults to the value of the variable `obarray'.  */)
   (Lisp_Object name, Lisp_Object obarray)
 {
   register Lisp_Object string, tem;
-  int hash;
+  size_t hash;
 
   if (NILP (obarray)) obarray = Vobarray;
   obarray = check_obarray (obarray);
@@ -3824,8 +3824,8 @@ OBARRAY defaults to the value of the variable `obarray'.  */)
 Lisp_Object
 oblookup (Lisp_Object obarray, register const char *ptr, EMACS_INT size, EMACS_INT size_byte)
 {
-  int hash;
-  int obsize;
+  size_t hash;
+  size_t obsize;
   register Lisp_Object tail;
   Lisp_Object bucket, tem;
 
@@ -3858,21 +3858,21 @@ oblookup (Lisp_Object obarray, register const char *ptr, EMACS_INT size, EMACS_I
   return tem;
 }
 
-static int
-hash_string (const char *ptr, int len)
+static size_t
+hash_string (const char *ptr, size_t len)
 {
   register const char *p = ptr;
   register const char *end = p + len;
   register unsigned char c;
-  register int hash = 0;
+  register size_t hash = 0;
 
   while (p != end)
     {
       c = *p++;
       if (c >= 0140) c -= 40;
-      hash = ((hash<<3) + (hash>>28) + c);
+      hash = (hash << 3) + (hash >> (CHAR_BIT * sizeof hash - 4)) + c;
     }
-  return hash & 07777777777;
+  return hash;
 }
 \f
 void