1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-02-23 00:10:48 -08:00

Avoid overexposing fixnums for hash codes

Following a suggestion by Stefan Monnier in:
https://lists.gnu.org/r/emacs-devel/2019-07/msg00530.html
* doc/lispref/hash.texi (Creating Hash, Defining Hash):
* src/fns.c (Fsxhash_eq, Fsxhash_eql, Fsxhash_equal, Fmake_hash_table):
Don’t insist that hash codes be fixnums, reverting
the recent doc changes to the contrary.
* src/bytecode.c (exec_byte_code): Special-case only the eq case,
as the others aren’t worth tuning now that we treat bignum hashes
like fixnums.
* src/fns.c (hashfn_user_defined): If the hash code is a bignum,
reduce its hash down to a fixnum.
This commit is contained in:
Paul Eggert 2019-07-22 21:27:33 -07:00
parent 97477edaf2
commit f378ed1a0b
3 changed files with 19 additions and 23 deletions

View file

@ -1406,18 +1406,12 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
/* h->count is a faster approximation for HASH_TABLE_SIZE (h)
here. */
if (h->count <= 5)
if (h->count <= 5 && !h->test.cmpfn)
{ /* Do a linear search if there are not many cases
FIXME: 5 is arbitrarily chosen. */
Lisp_Object hash_code
= h->test.cmpfn ? h->test.hashfn (v1, h) : Qnil;
for (i = h->count; 0 <= --i; )
if (EQ (v1, HASH_KEY (h, i))
|| (h->test.cmpfn
&& EQ (hash_code, HASH_HASH (h, i))
&& !NILP (h->test.cmpfn (v1, HASH_KEY (h, i), h))))
break;
for (i = h->count; 0 <= --i; )
if (EQ (v1, HASH_KEY (h, i)))
break;
}
else
i = hash_lookup (h, v1, NULL);