diff options
-rw-r--r-- | src/ChangeLog | 9 | ||||
-rw-r--r-- | src/fns.c | 19 | ||||
-rw-r--r-- | src/lisp.h | 11 | ||||
-rw-r--r-- | src/profiler.c | 2 |
4 files changed, 26 insertions, 15 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 45e97ddd93c..c759b026dba 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +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) diff --git a/src/fns.c b/src/fns.c index 6faaa67152e..f83cdaa243c 100644 --- a/src/fns.c +++ b/src/fns.c @@ -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); } diff --git a/src/lisp.h b/src/lisp.h index cac7d4b7012..ce805e96c96 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -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. */ diff --git a/src/profiler.c b/src/profiler.c index 6f112440902..365d834b9e1 100644 --- a/src/profiler.c +++ b/src/profiler.c @@ -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); } |