- if (ht_key_equals(e_key, key_hash, key_data, key_len)) {
- TRACE("h1", "hti_lookup: entry %p key \"%s\"", e, GET_PTR(e_key)->data);
- TRACE("h2", "hti_lookup: entry key len %llu, value %p", GET_PTR(e_key)->len, e->value);
- return e;
+ // Compare <key> with the key in the entry.
+ if (EXPECT_TRUE(hti->ht->key_type == NULL)) {
+ // fast path for integer keys
+ if (ent_key == (uint64_t)key) {
+ TRACE("h1", "hti_lookup: found entry %p with key %p", ent, ent_key);
+ return ent;
+ }
+ } else {
+ // The key in <ent> is made up of two parts. The 48 low-order bits are a pointer. The
+ // high-order 16 bits are taken from the hash. The bits from the hash are used as a
+ // quick check to rule out non-equal keys without doing a complete compare.
+ if ((key_hash >> 16) == (ent_key >> 48) && hti->ht->key_type->cmp(GET_PTR(ent_key), key) == 0) {
+ TRACE("h1", "hti_lookup: found entry %p with key %p", ent, GET_PTR(ent_key));
+ return ent;
+ }