From: Ripduman Sohan <[email protected]>

Used the precomputed hash value as a primary indicator for optimising
lookups and changes.  We only do a memcmp() on lookup if item hash
matches the hash of the key we're interested in (assumes non-perfect
hashing).  Same for lookup.  When rehashing on expansion of the hash
table we avoid recomputing the item hash.

Signed-off-by: Ripduman Sohan <[email protected]>
---
 engines/default_engine/assoc.c |   15 +++++----------
 1 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/engines/default_engine/assoc.c b/engines/default_engine/assoc.c
index feeacd1..74ac12d 100644
--- a/engines/default_engine/assoc.c
+++ b/engines/default_engine/assoc.c
@@ -96,7 +96,7 @@ hash_item *assoc_find(struct default_engine *engine, uint32_t 
hash, const char *
     hash_item *ret = NULL;
     int depth = 0;
     while (it) {
-        if ((nkey == it->nkey) && (memcmp(key, item_get_key(it), nkey) == 0)) {
+        if ((hash == it->hash) && (nkey == it->nkey) && (memcmp(key, 
item_get_key(it), nkey) == 0)) {
             ret = it;
             break;
         }
@@ -114,11 +114,10 @@ hash_item *assoc_find(struct default_engine *engine, 
uint32_t hash, const char *
 
 static inline hash_item** _hashitem_before(struct default_engine *engine,
                                     struct assoc_bucket *bucket,
-                                    const char *key,
-                                    const size_t nkey) {
+                                    hash_item *it) {
     hash_item **pos = &bucket->head;
 
-    while (*pos && ((nkey != (*pos)->nkey) || memcmp(key, item_get_key(*pos), 
nkey))) {
+    while (*pos && ((it->hash != (*pos)->hash) || memcmp(item_get_key(it), 
item_get_key(*pos), it->nkey))) {
         pos = &(*pos)->h_next;
     }
     return pos;
@@ -198,7 +197,7 @@ void assoc_delete(struct default_engine *engine, hash_item 
*it) {
 
     struct assoc_bucket *bucket= get_assoc_bucket_ref(engine, it->hash, 1);
 
-    hash_item **before = _hashitem_before(engine, bucket, item_get_key(it), 
it->nkey);
+    hash_item **before = _hashitem_before(engine, bucket, it);
 
     if (*before) {
         hash_item *nxt;
@@ -214,9 +213,6 @@ void assoc_delete(struct default_engine *engine, hash_item 
*it) {
         return;
     }
     put_assoc_bucket_ref(engine, bucket);
-    /* Note:  we never actually get here.  the callers don't delete things
-       they can't find. */
-    assert(*before != 0);
 }
 
 
@@ -239,8 +235,7 @@ static void *assoc_maintenance_thread(void *arg) {
                  NULL != it; it = next) {
                 next = it->h_next;
 
-                bucket = engine->server.core->hash(item_get_key(it), it->nkey, 
0)
-                    & hashmask(engine->assoc.hashpower);
+                bucket = it->hash & hashmask(engine->assoc.hashpower);
                 it->h_next = engine->assoc.primary_hashtable[bucket].head;
                 engine->assoc.primary_hashtable[bucket].head = it;
             }
-- 
1.7.1

Reply via email to