]> git.saurik.com Git - redis.git/commitdiff
Faster version of the function hashing possibly encoded objects, leading to a general...
authorantirez <antirez@gmail.com>
Tue, 2 Feb 2010 11:19:24 +0000 (12:19 +0100)
committerantirez <antirez@gmail.com>
Tue, 2 Feb 2010 11:19:24 +0000 (12:19 +0100)
redis.c

diff --git a/redis.c b/redis.c
index e095e6952ec6351b46f7d984a185f3b24d3a2ba1..87711dabb13c68a08f44b2dd7c5853fb4b974f1f 100644 (file)
--- a/redis.c
+++ b/redis.c
@@ -954,10 +954,24 @@ static int dictEncObjKeyCompare(void *privdata, const void *key1,
 static unsigned int dictEncObjHash(const void *key) {
     robj *o = (robj*) key;
 
-    o = getDecodedObject(o);
-    unsigned int hash = dictGenHashFunction(o->ptr, sdslen((sds)o->ptr));
-    decrRefCount(o);
-    return hash;
+    if (o->encoding == REDIS_ENCODING_RAW) {
+        return dictGenHashFunction(o->ptr, sdslen((sds)o->ptr));
+    } else {
+        if (o->encoding == REDIS_ENCODING_INT) {
+            char buf[32];
+            int len;
+
+            len = snprintf(buf,32,"%ld",(long)o->ptr);
+            return dictGenHashFunction((unsigned char*)buf, len);
+        } else {
+            unsigned int hash;
+
+            o = getDecodedObject(o);
+            hash = dictGenHashFunction(o->ptr, sdslen((sds)o->ptr));
+            decrRefCount(o);
+            return hash;
+        }
+    }
 }
 
 /* Sets type and expires */