From: Stefan Monnier Date: Thu, 8 Nov 2012 21:58:55 +0000 (-0500) Subject: * src/lisp.h (XHASH): Redefine to be imperfect and fit in a Lisp int. X-Git-Tag: emacs-24.3.90~173^2~18^2~156 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=61ddb1b9e10518fe3e5c66a255119de92b48f2a0;p=emacs.git * src/lisp.h (XHASH): Redefine to be imperfect and fit in a Lisp int. * src/fns.c (hashfn_eq, hashfn_eql, sxhash): * src/profiler.c (hashfn_profiler): Don't use XUINT on non-integers. * src/buffer.c (compare_overlays): Use XLI rather than XHASH. --- diff --git a/src/ChangeLog b/src/ChangeLog index c759b026dba..a8f1abd799f 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2012-11-08 Stefan Monnier + + * lisp.h (XHASH): Redefine to be imperfect and fit in a Lisp int. + * fns.c (hashfn_eq, hashfn_eql, sxhash): + * profiler.c (hashfn_profiler): Don't use XUINT on non-integers. + * buffer.c (compare_overlays): Use XLI rather than XHASH. + 2012-11-08 Paul Eggert Use same hash function for hashfn_profiler as for hash_string etc. diff --git a/src/buffer.c b/src/buffer.c index 1d58df54f6f..619a729a859 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -3132,8 +3132,8 @@ compare_overlays (const void *v1, const void *v2) between "equal" overlays. The result can still change between invocations of Emacs, but it won't change in the middle of `find_field' (bug#6830). */ - if (XHASH (s1->overlay) != XHASH (s2->overlay)) - return XHASH (s1->overlay) < XHASH (s2->overlay) ? -1 : 1; + if (!EQ (s1->overlay, s2->overlay)) + return XLI (s1->overlay) < XLI (s2->overlay) ? -1 : 1; return 0; } diff --git a/src/fns.c b/src/fns.c index f83cdaa243c..c07c013ccc7 100644 --- a/src/fns.c +++ b/src/fns.c @@ -3479,7 +3479,7 @@ cmpfn_user_defined (struct hash_table_test *ht, static EMACS_UINT hashfn_eq (struct hash_table_test *ht, Lisp_Object key) { - EMACS_UINT hash = XUINT (key) ^ XTYPE (key); + EMACS_UINT hash = XHASH (key) ^ XTYPE (key); return hash; } @@ -3494,7 +3494,7 @@ hashfn_eql (struct hash_table_test *ht, Lisp_Object key) if (FLOATP (key)) hash = sxhash (key, 0); else - hash = XUINT (key) ^ XTYPE (key); + hash = XHASH (key) ^ XTYPE (key); return hash; } @@ -4173,7 +4173,7 @@ sxhash (Lisp_Object obj, int depth) break; case Lisp_Misc: - hash = XUINT (obj); + hash = XHASH (obj); break; case Lisp_Symbol: @@ -4197,7 +4197,7 @@ sxhash (Lisp_Object obj, int depth) else /* Others are `equal' if they are `eq', so let's take their address as hash. */ - hash = XUINT (obj); + hash = XHASH (obj); break; case Lisp_Cons: diff --git a/src/lisp.h b/src/lisp.h index ce805e96c96..d940df196e8 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -454,9 +454,6 @@ enum More_Lisp_Bits For example, if tem is a Lisp_Object whose type is Lisp_Cons, XCONS (tem) is the struct Lisp_Cons * pointing to the memory for that cons. */ -/* Return a perfect hash of the Lisp_Object representation. */ -#define XHASH(a) XLI (a) - #if USE_LSB_TAG enum lsb_bits @@ -509,6 +506,11 @@ static EMACS_INT const VALMASK #endif /* not USE_LSB_TAG */ +/* Return a (Lisp-integer sized) hash of the Lisp_Object value. Happens to be + like XUINT right now, but XUINT should only be applied to objects we know + are integers. */ +#define XHASH(a) XUINT (a) + /* For integers known to be positive, XFASTINT sometimes provides faster retrieval and XSETFASTINT provides faster storage. If not, fallback on the non-accelerated path. */ @@ -524,7 +526,7 @@ static EMACS_INT const VALMASK # define XUNTAG(a, type) XPNTR (a) #endif -#define EQ(x, y) (XHASH (x) == XHASH (y)) +#define EQ(x, y) (XLI (x) == XLI (y)) /* Largest and smallest representable fixnum values. These are the C values. They are macros for use in static initializers. */ diff --git a/src/print.c b/src/print.c index af6eda7298f..bf86be5622e 100644 --- a/src/print.c +++ b/src/print.c @@ -798,7 +798,7 @@ safe_debug_print (Lisp_Object arg) else fprintf (stderr, "#<%s_LISP_OBJECT 0x%08"pI"x>\r\n", !valid ? "INVALID" : "SOME", - XHASH (arg)); + XLI (arg)); } diff --git a/src/profiler.c b/src/profiler.c index 365d834b9e1..3d8f7243d2f 100644 --- a/src/profiler.c +++ b/src/profiler.c @@ -555,15 +555,15 @@ hashfn_profiler (struct hash_table_test *ht, Lisp_Object bt) { Lisp_Object f = AREF (bt, i); EMACS_UINT hash1 - = (COMPILEDP (f) ? XUINT (AREF (f, COMPILED_BYTECODE)) + = (COMPILEDP (f) ? XHASH (AREF (f, COMPILED_BYTECODE)) : (CONSP (f) && CONSP (XCDR (f)) && EQ (Qclosure, XCAR (f))) - ? XUINT (XCDR (XCDR (f))) : XUINT (f)); + ? XHASH (XCDR (XCDR (f))) : XHASH (f)); hash = sxhash_combine (hash, hash1); } return (hash & INTMASK); } else - return XUINT (bt); + return XHASH (bt); } void