aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2013-02-09 14:42:33 -0800
committerPaul Eggert2013-02-09 14:42:33 -0800
commiteff1c1900f47ec5dfb6d435325b366362d09d2db (patch)
tree9db491fe10a82b95f493b8ae6cdfc3d56103b2fa /src
parent4dde2087c47f0ef2a97c3b39d89b94b8a47baf37 (diff)
downloademacs-eff1c1900f47ec5dfb6d435325b366362d09d2db.tar.gz
emacs-eff1c1900f47ec5dfb6d435325b366362d09d2db.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog12
-rw-r--r--src/fns.c6
-rw-r--r--src/lisp.h10
-rw-r--r--src/profiler.c2
4 files changed, 23 insertions, 7 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index cfe59c2ec88..05d69382855 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,15 @@
12013-02-09 Paul Eggert <eggert@cs.ucla.edu>
2
3 Minor hashing refactoring.
4 * fns.c (SXHASH_REDUCE): Move to lisp.h.
5 (sxhash_float): Return EMACS_UINT, for consistency with the other
6 hash functions.
7 * lisp.h (INTMASK): Now a macro, since SXHASH_REDUCE is now a
8 non-static inline function and therefore can't use static vars.
9 (SXHASH_REDUCE): Move here from fns.c, and make it inline.
10 * profiler.c (hashfn_profiler): Use SXHASH_REDUCE, to be consistent
11 with the other hash functions.
12
12013-02-09 Eli Zaretskii <eliz@gnu.org> 132013-02-09 Eli Zaretskii <eliz@gnu.org>
2 14
3 * callproc.c (Fcall_process_region) [WINDOWSNT]: Make sure the 15 * callproc.c (Fcall_process_region) [WINDOWSNT]: Make sure the
diff --git a/src/fns.c b/src/fns.c
index ecd1a31335a..527976593da 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -4045,10 +4045,6 @@ sweep_weak_hash_tables (void)
4045 4045
4046#define SXHASH_MAX_LEN 7 4046#define SXHASH_MAX_LEN 7
4047 4047
4048/* Hash X, returning a value that fits into a Lisp integer. */
4049#define SXHASH_REDUCE(X) \
4050 ((((X) ^ (X) >> (BITS_PER_EMACS_INT - FIXNUM_BITS))) & INTMASK)
4051
4052/* Return a hash for string PTR which has length LEN. The hash value 4048/* Return a hash for string PTR which has length LEN. The hash value
4053 can be any EMACS_UINT value. */ 4049 can be any EMACS_UINT value. */
4054 4050
@@ -4081,7 +4077,7 @@ sxhash_string (char const *ptr, ptrdiff_t len)
4081 4077
4082/* Return a hash for the floating point value VAL. */ 4078/* Return a hash for the floating point value VAL. */
4083 4079
4084static EMACS_INT 4080static EMACS_UINT
4085sxhash_float (double val) 4081sxhash_float (double val)
4086{ 4082{
4087 EMACS_UINT hash = 0; 4083 EMACS_UINT hash = 0;
diff --git a/src/lisp.h b/src/lisp.h
index c15e83bd51c..14db66c6793 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -227,7 +227,7 @@ enum enum_USE_LSB_TAG { USE_LSB_TAG = 0 };
227 227
228/* Lisp integers use 2 tags, to give them one extra bit, thus 228/* Lisp integers use 2 tags, to give them one extra bit, thus
229 extending their range from, e.g., -2^28..2^28-1 to -2^29..2^29-1. */ 229 extending their range from, e.g., -2^28..2^28-1 to -2^29..2^29-1. */
230static EMACS_INT const INTMASK = EMACS_INT_MAX >> (INTTYPEBITS - 1); 230#define INTMASK (EMACS_INT_MAX >> (INTTYPEBITS - 1))
231#define case_Lisp_Int case Lisp_Int0: case Lisp_Int1 231#define case_Lisp_Int case Lisp_Int0: case Lisp_Int1
232#define LISP_INT_TAG_P(x) (((x) & ~Lisp_Int1) == 0) 232#define LISP_INT_TAG_P(x) (((x) & ~Lisp_Int1) == 0)
233 233
@@ -1304,6 +1304,14 @@ sxhash_combine (EMACS_UINT x, EMACS_UINT y)
1304 return (x << 4) + (x >> (BITS_PER_EMACS_INT - 4)) + y; 1304 return (x << 4) + (x >> (BITS_PER_EMACS_INT - 4)) + y;
1305} 1305}
1306 1306
1307/* Hash X, returning a value that fits into a fixnum. */
1308
1309LISP_INLINE EMACS_UINT
1310SXHASH_REDUCE (EMACS_UINT x)
1311{
1312 return (x ^ x >> (BITS_PER_EMACS_INT - FIXNUM_BITS)) & INTMASK;
1313}
1314
1307/* These structures are used for various misc types. */ 1315/* These structures are used for various misc types. */
1308 1316
1309struct Lisp_Misc_Any /* Supertype of all Misc types. */ 1317struct Lisp_Misc_Any /* Supertype of all Misc types. */
diff --git a/src/profiler.c b/src/profiler.c
index f6503cf182e..85d9c1ca88a 100644
--- a/src/profiler.c
+++ b/src/profiler.c
@@ -560,7 +560,7 @@ hashfn_profiler (struct hash_table_test *ht, Lisp_Object bt)
560 ? XHASH (XCDR (XCDR (f))) : XHASH (f)); 560 ? XHASH (XCDR (XCDR (f))) : XHASH (f));
561 hash = sxhash_combine (hash, hash1); 561 hash = sxhash_combine (hash, hash1);
562 } 562 }
563 return (hash & INTMASK); 563 return SXHASH_REDUCE (hash);
564 } 564 }
565 else 565 else
566 return XHASH (bt); 566 return XHASH (bt);