From 671adc0de2203df2a1ff6b112dca3942c699de1c Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Sat, 9 Jul 2016 06:13:54 -0600 Subject: [PATCH] tweaks to hashing Faster hasing of booleans, correct potential loss of distinction for a compound structure that ends in a symbol or keyword, and shortcuiting lookup in an empty immutable hash table. --- racket/src/racket/src/hash.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/racket/src/racket/src/hash.c b/racket/src/racket/src/hash.c index cf2304f49f..74171890c6 100644 --- a/racket/src/racket/src/hash.c +++ b/racket/src/racket/src/hash.c @@ -1368,9 +1368,14 @@ XFORM_NONGCING static uintptr_t fast_equal_hash_key(Scheme_Object *o, uintptr_t top: t = SCHEME_TYPE(o); - k += t; switch(t) { + case scheme_true_type: + return k + PTR_TO_LONG(o); + break; + case scheme_false_type: + return k + PTR_TO_LONG(o); + break; case scheme_integer_type: { uintptr_t iv = to_unsigned_hash(SCHEME_INT_VAL(o)); @@ -1484,7 +1489,7 @@ XFORM_NONGCING static uintptr_t fast_equal_hash_key(Scheme_Object *o, uintptr_t # else case scheme_keyword_type: case scheme_symbol_type: - return PTR_TO_LONG(o); + return k + PTR_TO_LONG(o); # endif default: { @@ -1889,7 +1894,7 @@ intptr_t scheme_equal_hash_key(Scheme_Object *o) uintptr_t k; int done = 1; - k = fast_equal_hash_key(o, 0, &done); + k = fast_equal_hash_key(o, SCHEME_TYPE(o), &done); if (done) return to_signed_hash(k); else @@ -1917,6 +1922,10 @@ XFORM_NONGCING static uintptr_t fast_equal_hash_key2(Scheme_Object *o, int *_don *_done = 1; switch(t) { + case scheme_true_type: + return 1; + case scheme_false_type: + return 2; case scheme_integer_type: return t - SCHEME_INT_VAL(o); #ifdef MZ_USE_SINGLE_FLOATS @@ -3202,6 +3211,9 @@ Scheme_Object *scheme_hash_tree_get_w_key_wraps(Scheme_Hash_Tree *tree, Scheme_O int stype, pos; tree = resolve_placeholder(tree); + if (!tree->count) + return NULL; + stype = SCHEME_TYPE(tree); if (stype == scheme_eq_hash_tree_type)