From afcbcc0e58749ebbebcd595c120d17a0e3dbb82e Mon Sep 17 00:00:00 2001 From: oranagra Date: Mon, 9 May 2016 18:01:09 +0300 Subject: dict.c: introduce dictUnlink(). Notes by @antirez: This patch was picked from a larger commit by Oran and adapted to change the API a bit. The basic idea is to avoid double lookups when there is to use the value of the deleted entry. BEFORE: entry = dictFind( ... ); /* 1st lookup. */ /* Do somethjing with the entry. */ dictDelete(...); /* 2nd lookup. */ AFTER: entry = dictUnlink( ... ); /* 1st lookup. */ /* Do somethjing with the entry. */ dictFreeUnlinkedEntry(entry); /* No lookups!. */ --- src/dict.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/dict.h') diff --git a/src/dict.h b/src/dict.h index 739de68ef..406fa36d8 100644 --- a/src/dict.h +++ b/src/dict.h @@ -154,7 +154,8 @@ dictEntry *dictAddRaw(dict *d, void *key, dictEntry **existing); int dictReplace(dict *d, void *key, void *val); dictEntry *dictReplaceRaw(dict *d, void *key); int dictDelete(dict *d, const void *key); -int dictDeleteNoFree(dict *d, const void *key); +dictEntry *dictUnlink(dict *ht, const void *key); +void dictFreeUnlinkedEntry(dict *d, dictEntry *he); void dictRelease(dict *d); dictEntry * dictFind(dict *d, const void *key); void *dictFetchValue(dict *d, const void *key); -- cgit v1.2.1