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
/* 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. */
(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);
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;
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