Commit 04a2d0d3 authored by Paul Eggert's avatar Paul Eggert
Browse files

Use same hash function for hashfn_profiler as for hash_string etc.

* fns.c (SXHASH_COMBINE): Remove.  All uses replaced by sxhash_combine.
* lisp.h (sxhash_combine): New inline function, with the contents
of the old SXHASH_COMBINE.
* profiler.c (hashfn_profiler): Use it, instead of having a
special hash function containing a comparison that always yields 1.
parent de5ef41a
2012-11-08 Paul Eggert <eggert@cs.ucla.edu>
Use same hash function for hashfn_profiler as for hash_string etc.
* fns.c (SXHASH_COMBINE): Remove. All uses replaced by sxhash_combine.
* lisp.h (sxhash_combine): New inline function, with the contents
of the old SXHASH_COMBINE.
* profiler.c (hashfn_profiler): Use it, instead of having a
special hash function containing a comparison that always yields 1.
2012-11-08 Stefan Monnier <monnier@iro.umontreal.ca>
 
* xfaces.c (Qultra_light, Qreverse_oblique, Qreverse_italic)
......
......@@ -4036,13 +4036,6 @@ sweep_weak_hash_tables (void)
#define SXHASH_MAX_LEN 7
/* Combine two integers X and Y for hashing. The result might not fit
into a Lisp integer. */
#define SXHASH_COMBINE(X, Y) \
((((EMACS_UINT) (X) << 4) + ((EMACS_UINT) (X) >> (BITS_PER_EMACS_INT - 4))) \
+ (EMACS_UINT) (Y))
/* Hash X, returning a value that fits into a Lisp integer. */
#define SXHASH_REDUCE(X) \
((((X) ^ (X) >> (BITS_PER_EMACS_INT - FIXNUM_BITS))) & INTMASK)
......@@ -4061,7 +4054,7 @@ hash_string (char const *ptr, ptrdiff_t len)
while (p != end)
{
c = *p++;
hash = SXHASH_COMBINE (hash, c);
hash = sxhash_combine (hash, c);
}
return hash;
......@@ -4095,7 +4088,7 @@ sxhash_float (double val)
u.val = val;
memset (&u.val + 1, 0, sizeof u - sizeof u.val);
for (i = 0; i < WORDS_PER_DOUBLE; i++)
hash = SXHASH_COMBINE (hash, u.word[i]);
hash = sxhash_combine (hash, u.word[i]);
return SXHASH_REDUCE (hash);
}
......@@ -4114,13 +4107,13 @@ sxhash_list (Lisp_Object list, int depth)
list = XCDR (list), ++i)
{
EMACS_UINT hash2 = sxhash (XCAR (list), depth + 1);
hash = SXHASH_COMBINE (hash, hash2);
hash = sxhash_combine (hash, hash2);
}
if (!NILP (list))
{
EMACS_UINT hash2 = sxhash (list, depth + 1);
hash = SXHASH_COMBINE (hash, hash2);
hash = sxhash_combine (hash, hash2);
}
return SXHASH_REDUCE (hash);
......@@ -4140,7 +4133,7 @@ sxhash_vector (Lisp_Object vec, int depth)
for (i = 0; i < n; ++i)
{
EMACS_UINT hash2 = sxhash (AREF (vec, i), depth + 1);
hash = SXHASH_COMBINE (hash, hash2);
hash = sxhash_combine (hash, hash2);
}
return SXHASH_REDUCE (hash);
......@@ -4156,7 +4149,7 @@ sxhash_bool_vector (Lisp_Object vec)
n = min (SXHASH_MAX_LEN, XBOOL_VECTOR (vec)->header.size);
for (i = 0; i < n; ++i)
hash = SXHASH_COMBINE (hash, XBOOL_VECTOR (vec)->data[i]);
hash = sxhash_combine (hash, XBOOL_VECTOR (vec)->data[i]);
return SXHASH_REDUCE (hash);
}
......
......@@ -438,7 +438,7 @@ enum More_Lisp_Bits
/* To calculate the memory footprint of the pseudovector, it's useful
to store the size of non-Lisp area in word_size units here. */
PSEUDOVECTOR_REST_BITS = 12,
PSEUDOVECTOR_REST_MASK = (((1 << PSEUDOVECTOR_REST_BITS) - 1)
PSEUDOVECTOR_REST_MASK = (((1 << PSEUDOVECTOR_REST_BITS) - 1)
<< PSEUDOVECTOR_SIZE_BITS),
/* Used to extract pseudovector subtype information. */
......@@ -1284,6 +1284,15 @@ static double const DEFAULT_REHASH_THRESHOLD = 0.8;
static double const DEFAULT_REHASH_SIZE = 1.5;
/* Combine two integers X and Y for hashing. The result might not fit
into a Lisp integer. */
LISP_INLINE EMACS_UINT
sxhash_combine (EMACS_UINT x, EMACS_UINT y)
{
return (x << 4) + (x >> (BITS_PER_EMACS_INT - 4)) + y;
}
/* These structures are used for various misc types. */
struct Lisp_Misc_Any /* Supertype of all Misc types. */
......
......@@ -558,7 +558,7 @@ hashfn_profiler (struct hash_table_test *ht, Lisp_Object bt)
= (COMPILEDP (f) ? XUINT (AREF (f, COMPILED_BYTECODE))
: (CONSP (f) && CONSP (XCDR (f)) && EQ (Qclosure, XCAR (f)))
? XUINT (XCDR (XCDR (f))) : XUINT (f));
hash = hash1 + (hash << 1) + (hash == (EMACS_INT) hash);
hash = sxhash_combine (hash, hash1);
}
return (hash & INTMASK);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment