]> code.delx.au - gnu-emacs/commitdiff
Use same hash function for hashfn_profiler as for hash_string etc.
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 8 Nov 2012 21:43:34 +0000 (13:43 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 8 Nov 2012 21:43:34 +0000 (13:43 -0800)
* 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.

src/ChangeLog
src/fns.c
src/lisp.h
src/profiler.c

index 45e97ddd93c71fd79de753714d7bb5691a694d7e..c759b026dba96b76b4b7fe44aedff440c390c2ae 100644 (file)
@@ -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)
index 6faaa67152e886b55cfa31a897296cce038a25f1..f83cdaa243c93fe533957e291db107e8bb60f6a7 100644 (file)
--- 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);
 }
index cac7d4b701292aeb4189b6ceaf528b95dfdcf0ef..ce805e96c96ecbdb8972617902ea7f2557fd9af6 100644 (file)
@@ -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.  */
index 6f112440902f265d55f251d3237c3ca83e1dc313..365d834b9e1195f58e6bcd53eb28fe237a0d7059 100644 (file)
@@ -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);
     }