]> code.delx.au - gnu-emacs/commitdiff
Minor hashing refactoring.
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 9 Feb 2013 22:42:33 +0000 (14:42 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 9 Feb 2013 22:42:33 +0000 (14:42 -0800)
* fns.c (SXHASH_REDUCE): Move to lisp.h.
(sxhash_float): Return EMACS_UINT, for consistency with the other
hash functions.
* lisp.h (INTMASK): Now a macro, since SXHASH_REDUCE is now a
non-static inline function and therefore can't use static vars.
(SXHASH_REDUCE): Move here from fns.c, and make it inline.
* profiler.c (hashfn_profiler): Use SXHASH_REDUCE, to be consistent
with the other hash functions.

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

index cfe59c2ec88c512e32964563b7a33d120c35cbd0..05d69382855f98cfbccfc75b595988eebac1388b 100644 (file)
@@ -1,3 +1,15 @@
+2013-02-09  Paul Eggert  <eggert@cs.ucla.edu>
+
+       Minor hashing refactoring.
+       * fns.c (SXHASH_REDUCE): Move to lisp.h.
+       (sxhash_float): Return EMACS_UINT, for consistency with the other
+       hash functions.
+       * lisp.h (INTMASK): Now a macro, since SXHASH_REDUCE is now a
+       non-static inline function and therefore can't use static vars.
+       (SXHASH_REDUCE): Move here from fns.c, and make it inline.
+       * profiler.c (hashfn_profiler): Use SXHASH_REDUCE, to be consistent
+       with the other hash functions.
+
 2013-02-09  Eli Zaretskii  <eliz@gnu.org>
 
        * callproc.c (Fcall_process_region) [WINDOWSNT]: Make sure the
index ecd1a31335a6a715917df3d95d2383a0d7257170..527976593daef89ded6bdb7dc75d013f941b37ce 100644 (file)
--- a/src/fns.c
+++ b/src/fns.c
@@ -4045,10 +4045,6 @@ sweep_weak_hash_tables (void)
 
 #define SXHASH_MAX_LEN   7
 
-/* Hash X, returning a value that fits into a Lisp integer.  */
-#define SXHASH_REDUCE(X) \
-  ((((X) ^ (X) >> (BITS_PER_EMACS_INT - FIXNUM_BITS))) & INTMASK)
-
 /* Return a hash for string PTR which has length LEN.  The hash value
    can be any EMACS_UINT value.  */
 
@@ -4081,7 +4077,7 @@ sxhash_string (char const *ptr, ptrdiff_t len)
 
 /* Return a hash for the floating point value VAL.  */
 
-static EMACS_INT
+static EMACS_UINT
 sxhash_float (double val)
 {
   EMACS_UINT hash = 0;
index c15e83bd51caa9569d1fa534114a035c9cdf6863..14db66c67931adc7a6aec99c7dbfde0a19cef27c 100644 (file)
@@ -227,7 +227,7 @@ enum enum_USE_LSB_TAG { USE_LSB_TAG = 0 };
 
 /* Lisp integers use 2 tags, to give them one extra bit, thus
    extending their range from, e.g., -2^28..2^28-1 to -2^29..2^29-1.  */
-static EMACS_INT const INTMASK = EMACS_INT_MAX >> (INTTYPEBITS - 1);
+#define INTMASK (EMACS_INT_MAX >> (INTTYPEBITS - 1))
 #define case_Lisp_Int case Lisp_Int0: case Lisp_Int1
 #define LISP_INT_TAG_P(x) (((x) & ~Lisp_Int1) == 0)
 
@@ -1304,6 +1304,14 @@ sxhash_combine (EMACS_UINT x, EMACS_UINT y)
   return (x << 4) + (x >> (BITS_PER_EMACS_INT - 4)) + y;
 }
 
+/* Hash X, returning a value that fits into a fixnum.  */
+
+LISP_INLINE EMACS_UINT
+SXHASH_REDUCE (EMACS_UINT x)
+{
+  return (x ^ x >> (BITS_PER_EMACS_INT - FIXNUM_BITS)) & INTMASK;
+}
+
 /* These structures are used for various misc types.  */
 
 struct Lisp_Misc_Any           /* Supertype of all Misc types.  */
index f6503cf182e9012b14c686a5b661ceae84c1416a..85d9c1ca88aeceb0c33e1db894cfe7114cd15405 100644 (file)
@@ -560,7 +560,7 @@ hashfn_profiler (struct hash_table_test *ht, Lisp_Object bt)
               ? XHASH (XCDR (XCDR (f))) : XHASH (f));
          hash = sxhash_combine (hash, hash1);
        }
-      return (hash & INTMASK);
+      return SXHASH_REDUCE (hash);
     }
   else
     return XHASH (bt);