summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2016-09-14 15:10:53 +0200
committerantirez <antirez@gmail.com>2016-09-14 16:37:53 +0200
commita636aeac07240fea0acb6066bf1752d0913a9b4e (patch)
tree844163d2dd60f463a7e6dfb509aa34480997b02c
parentafcbcc0e58749ebbebcd595c120d17a0e3dbb82e (diff)
downloadredis-a636aeac07240fea0acb6066bf1752d0913a9b4e.tar.gz
Apply the new dictUnlink() where possible.
Optimizations suggested and originally implemented by @oranagra. Re-applied by @antirez using the modified API.
-rw-r--r--src/dict.c3
-rw-r--r--src/lazyfree.c5
-rw-r--r--src/t_zset.c9
3 files changed, 9 insertions, 8 deletions
diff --git a/src/dict.c b/src/dict.c
index 322490283..5e327a794 100644
--- a/src/dict.c
+++ b/src/dict.c
@@ -478,8 +478,9 @@ dictEntry *dictUnlink(dict *ht, const void *key) {
}
/* You need to call this function to really free the entry after a call
- * to dictUnlink(). */
+ * to dictUnlink(). It's safe to call this function with 'he' = NULL. */
void dictFreeUnlinkedEntry(dict *d, dictEntry *he) {
+ if (he == NULL) return;
dictFreeKey(d, he);
dictFreeVal(d, he);
zfree(he);
diff --git a/src/lazyfree.c b/src/lazyfree.c
index dba3f00e2..c05252159 100644
--- a/src/lazyfree.c
+++ b/src/lazyfree.c
@@ -57,7 +57,7 @@ int dbAsyncDelete(redisDb *db, robj *key) {
/* If the value is composed of a few allocations, to free in a lazy way
* is actually just slower... So under a certain limit we just free
* the object synchronously. */
- dictEntry *de = dictFind(db->dict,key->ptr);
+ dictEntry *de = dictUnlink(db->dict,key->ptr);
if (de) {
robj *val = dictGetVal(de);
size_t free_effort = lazyfreeGetFreeEffort(val);
@@ -73,7 +73,8 @@ int dbAsyncDelete(redisDb *db, robj *key) {
/* Release the key-val pair, or just the key if we set the val
* field to NULL in order to lazy free it later. */
- if (dictDelete(db->dict,key->ptr) == DICT_OK) {
+ if (de) {
+ dictFreeUnlinkedEntry(db->dict,de);
if (server.cluster_enabled) slotToKeyDel(key);
return 1;
} else {
diff --git a/src/t_zset.c b/src/t_zset.c
index 81e6e57c5..8d905be02 100644
--- a/src/t_zset.c
+++ b/src/t_zset.c
@@ -1387,7 +1387,7 @@ int zsetDel(robj *zobj, sds ele) {
dictEntry *de;
double score;
- de = dictFind(zs->dict,ele);
+ de = dictUnlink(zs->dict,ele);
if (de != NULL) {
/* Get the score in order to delete from the skiplist later. */
score = *(double*)dictGetVal(de);
@@ -1397,12 +1397,11 @@ int zsetDel(robj *zobj, sds ele) {
* actually releases the SDS string representing the element,
* which is shared between the skiplist and the hash table, so
* we need to delete from the skiplist as the final step. */
- int retval1 = dictDelete(zs->dict,ele);
+ dictFreeUnlinkedEntry(zs->dict,de);
/* Delete from skiplist. */
- int retval2 = zslDelete(zs->zsl,score,ele,NULL);
-
- serverAssert(retval1 == DICT_OK && retval2);
+ int retval = zslDelete(zs->zsl,score,ele,NULL);
+ serverAssert(retval);
if (htNeedsResize(zs->dict)) dictResize(zs->dict);
return 1;