Skip to content

Commit

Permalink
Remove unused valDup (#443)
Browse files Browse the repository at this point in the history
Remove the unused value duplicate API from dict. It's unused in the codebase and introduces unnecessary overhead. 

---------

Signed-off-by: Eran Liberty <[email protected]>
  • Loading branch information
eliblight authored Jun 3, 2024
1 parent b95e7c3 commit 0700c44
Show file tree
Hide file tree
Showing 16 changed files with 8 additions and 46 deletions.
3 changes: 0 additions & 3 deletions src/cluster_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ static inline int defaultClientPort(void) {
dictType clusterNodesDictType = {
dictSdsHash, /* hash function */
NULL, /* key dup */
NULL, /* val dup */
dictSdsKeyCompare, /* key compare */
dictSdsDestructor, /* key destructor */
NULL, /* val destructor */
Expand All @@ -157,7 +156,6 @@ dictType clusterNodesDictType = {
dictType clusterNodesBlackListDictType = {
dictSdsCaseHash, /* hash function */
NULL, /* key dup */
NULL, /* val dup */
dictSdsKeyCaseCompare, /* key compare */
dictSdsDestructor, /* key destructor */
NULL, /* val destructor */
Expand All @@ -168,7 +166,6 @@ dictType clusterNodesBlackListDictType = {
dictType clusterSdsToListType = {
dictSdsHash, /* hash function */
NULL, /* key dup */
NULL, /* val dup */
dictSdsKeyCompare, /* key compare */
dictSdsDestructor, /* key destructor */
dictListDestructor, /* val destructor */
Expand Down
2 changes: 0 additions & 2 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,6 @@ void rewriteConfigSentinelOption(struct rewriteConfigState *state);
dictType optionToLineDictType = {
dictSdsCaseHash, /* hash function */
NULL, /* key dup */
NULL, /* val dup */
dictSdsKeyCaseCompare, /* key compare */
dictSdsDestructor, /* key destructor */
dictListDestructor, /* val destructor */
Expand All @@ -996,7 +995,6 @@ dictType optionToLineDictType = {
dictType optionSetDictType = {
dictSdsCaseHash, /* hash function */
NULL, /* key dup */
NULL, /* val dup */
dictSdsKeyCaseCompare, /* key compare */
dictSdsDestructor, /* key destructor */
NULL, /* val destructor */
Expand Down
5 changes: 4 additions & 1 deletion src/dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
#include "serverassert.h"
#include "monotonic.h"

#define UNUSED(V) ((void)V)

/* Using dictSetResizeEnabled() we make possible to disable
* resizing and rehashing of the hash table as needed. This is very important
* for us, as we use copy-on-write and don't want to move too much memory
Expand Down Expand Up @@ -800,8 +802,9 @@ void dictSetKey(dict *d, dictEntry *de, void *key) {
}

void dictSetVal(dict *d, dictEntry *de, void *val) {
UNUSED(d);
assert(entryHasValue(de));
de->v.val = d->type->valDup ? d->type->valDup(d, val) : val;
de->v.val = val;
}

void dictSetSignedIntegerVal(dictEntry *de, int64_t val) {
Expand Down
1 change: 0 additions & 1 deletion src/dict.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ typedef struct dictType {
/* Callbacks */
uint64_t (*hashFunction)(const void *key);
void *(*keyDup)(dict *d, const void *key);
void *(*valDup)(dict *d, const void *obj);
int (*keyCompare)(dict *d, const void *key1, const void *key2);
void (*keyDestructor)(dict *d, void *key);
void (*valDestructor)(dict *d, void *obj);
Expand Down
1 change: 0 additions & 1 deletion src/eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ static uint64_t dictStrCaseHash(const void *key) {
dictType shaScriptObjectDictType = {
dictStrCaseHash, /* hash function */
NULL, /* key dup */
NULL, /* val dup */
dictSdsKeyCaseCompare, /* key compare */
dictSdsDestructor, /* key destructor */
dictLuaScriptDestructor, /* val destructor */
Expand Down
1 change: 0 additions & 1 deletion src/expire.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,6 @@ void rememberSlaveKeyWithExpire(serverDb *db, robj *key) {
static dictType dt = {
dictSdsHash, /* hash function */
NULL, /* key dup */
NULL, /* val dup */
dictSdsKeyCompare, /* key compare */
dictSdsDestructor, /* key destructor */
NULL, /* val destructor */
Expand Down
5 changes: 0 additions & 5 deletions src/functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ typedef struct functionsLibMetaData {
dictType engineDictType = {
dictSdsCaseHash, /* hash function */
dictSdsDup, /* key dup */
NULL, /* val dup */
dictSdsKeyCaseCompare, /* key compare */
dictSdsDestructor, /* key destructor */
NULL, /* val destructor */
Expand All @@ -75,7 +74,6 @@ dictType engineDictType = {
dictType functionDictType = {
dictSdsCaseHash, /* hash function */
dictSdsDup, /* key dup */
NULL, /* val dup */
dictSdsKeyCaseCompare, /* key compare */
dictSdsDestructor, /* key destructor */
NULL, /* val destructor */
Expand All @@ -85,7 +83,6 @@ dictType functionDictType = {
dictType engineStatsDictType = {
dictSdsCaseHash, /* hash function */
dictSdsDup, /* key dup */
NULL, /* val dup */
dictSdsKeyCaseCompare, /* key compare */
dictSdsDestructor, /* key destructor */
engineStatsDispose, /* val destructor */
Expand All @@ -95,7 +92,6 @@ dictType engineStatsDictType = {
dictType libraryFunctionDictType = {
dictSdsHash, /* hash function */
dictSdsDup, /* key dup */
NULL, /* val dup */
dictSdsKeyCompare, /* key compare */
dictSdsDestructor, /* key destructor */
engineFunctionDispose, /* val destructor */
Expand All @@ -105,7 +101,6 @@ dictType libraryFunctionDictType = {
dictType librariesDictType = {
dictSdsHash, /* hash function */
dictSdsDup, /* key dup */
NULL, /* val dup */
dictSdsKeyCompare, /* key compare */
dictSdsDestructor, /* key destructor */
engineLibraryDispose, /* val destructor */
Expand Down
5 changes: 3 additions & 2 deletions src/kvstore.c
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,9 @@ void kvstoreDictSetKey(kvstore *kvs, int didx, dictEntry *de, void *key) {
}

void kvstoreDictSetVal(kvstore *kvs, int didx, dictEntry *de, void *val) {
dict *d = kvstoreGetDict(kvs, didx);
dictSetVal(d, de, val);
UNUSED(kvs);
UNUSED(didx);
dictSetVal(NULL, de, val);
}

dictEntry *
Expand Down
1 change: 0 additions & 1 deletion src/latency.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ void dictVanillaFree(dict *d, void *val);
dictType latencyTimeSeriesDictType = {
dictStringHash, /* hash function */
NULL, /* key dup */
NULL, /* val dup */
dictStringKeyCompare, /* key compare */
dictVanillaFree, /* key destructor */
dictVanillaFree, /* val destructor */
Expand Down
2 changes: 0 additions & 2 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -11780,7 +11780,6 @@ int dictCStringKeyCompare(dict *d, const void *key1, const void *key2) {
dictType moduleAPIDictType = {
dictCStringKeyHash, /* hash function */
NULL, /* key dup */
NULL, /* val dup */
dictCStringKeyCompare, /* key compare */
NULL, /* key destructor */
NULL, /* val destructor */
Expand Down Expand Up @@ -11811,7 +11810,6 @@ void moduleInitModulesSystemLast(void) {
dictType sdsKeyValueHashDictType = {
dictSdsCaseHash, /* hash function */
NULL, /* key dup */
NULL, /* val dup */
dictSdsKeyCaseCompare, /* key compare */
dictSdsDestructor, /* key destructor */
dictSdsDestructor, /* val destructor */
Expand Down
3 changes: 0 additions & 3 deletions src/sentinel.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,6 @@ void dictInstancesValDestructor(dict *d, void *obj) {
dictType instancesDictType = {
dictSdsHash, /* hash function */
NULL, /* key dup */
NULL, /* val dup */
dictSdsKeyCompare, /* key compare */
NULL, /* key destructor */
dictInstancesValDestructor, /* val destructor */
Expand All @@ -444,7 +443,6 @@ dictType instancesDictType = {
dictType leaderVotesDictType = {
dictSdsHash, /* hash function */
NULL, /* key dup */
NULL, /* val dup */
dictSdsKeyCompare, /* key compare */
NULL, /* key destructor */
NULL, /* val destructor */
Expand All @@ -455,7 +453,6 @@ dictType leaderVotesDictType = {
dictType renamedCommandsDictType = {
dictSdsCaseHash, /* hash function */
NULL, /* key dup */
NULL, /* val dup */
dictSdsKeyCaseCompare, /* key compare */
dictSdsDestructor, /* key destructor */
dictSdsDestructor, /* val destructor */
Expand Down
17 changes: 0 additions & 17 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,6 @@ int dictResizeAllowed(size_t moreMem, double usedRatio) {
dictType objectKeyPointerValueDictType = {
dictEncObjHash, /* hash function */
NULL, /* key dup */
NULL, /* val dup */
dictEncObjKeyCompare, /* key compare */
dictObjectDestructor, /* key destructor */
NULL, /* val destructor */
Expand All @@ -436,7 +435,6 @@ dictType objectKeyPointerValueDictType = {
dictType objectKeyHeapPointerValueDictType = {
dictEncObjHash, /* hash function */
NULL, /* key dup */
NULL, /* val dup */
dictEncObjKeyCompare, /* key compare */
dictObjectDestructor, /* key destructor */
dictVanillaFree, /* val destructor */
Expand All @@ -447,7 +445,6 @@ dictType objectKeyHeapPointerValueDictType = {
dictType setDictType = {
dictSdsHash, /* hash function */
NULL, /* key dup */
NULL, /* val dup */
dictSdsKeyCompare, /* key compare */
dictSdsDestructor, /* key destructor */
NULL, /* val destructor */
Expand All @@ -460,7 +457,6 @@ dictType setDictType = {
dictType zsetDictType = {
dictSdsHash, /* hash function */
NULL, /* key dup */
NULL, /* val dup */
dictSdsKeyCompare, /* key compare */
NULL, /* Note: SDS string shared & freed by skiplist */
NULL, /* val destructor */
Expand All @@ -471,7 +467,6 @@ dictType zsetDictType = {
dictType dbDictType = {
dictSdsHash, /* hash function */
NULL, /* key dup */
NULL, /* val dup */
dictSdsKeyCompare, /* key compare */
dictSdsDestructor, /* key destructor */
dictObjectDestructor, /* val destructor */
Expand All @@ -482,7 +477,6 @@ dictType dbDictType = {
dictType dbExpiresDictType = {
dictSdsHash, /* hash function */
NULL, /* key dup */
NULL, /* val dup */
dictSdsKeyCompare, /* key compare */
NULL, /* key destructor */
NULL, /* val destructor */
Expand All @@ -493,7 +487,6 @@ dictType dbExpiresDictType = {
dictType commandTableDictType = {
dictSdsCaseHash, /* hash function */
NULL, /* key dup */
NULL, /* val dup */
dictSdsKeyCaseCompare, /* key compare */
dictSdsDestructor, /* key destructor */
NULL, /* val destructor */
Expand All @@ -504,7 +497,6 @@ dictType commandTableDictType = {
dictType hashDictType = {
dictSdsHash, /* hash function */
NULL, /* key dup */
NULL, /* val dup */
dictSdsKeyCompare, /* key compare */
dictSdsDestructor, /* key destructor */
dictSdsDestructor, /* val destructor */
Expand All @@ -515,7 +507,6 @@ dictType hashDictType = {
dictType sdsReplyDictType = {
dictSdsHash, /* hash function */
NULL, /* key dup */
NULL, /* val dup */
dictSdsKeyCompare, /* key compare */
NULL, /* key destructor */
NULL, /* val destructor */
Expand All @@ -528,7 +519,6 @@ dictType sdsReplyDictType = {
dictType keylistDictType = {
dictObjHash, /* hash function */
NULL, /* key dup */
NULL, /* val dup */
dictObjKeyCompare, /* key compare */
dictObjectDestructor, /* key destructor */
dictListDestructor, /* val destructor */
Expand All @@ -540,7 +530,6 @@ dictType keylistDictType = {
dictType objToDictDictType = {
dictObjHash, /* hash function */
NULL, /* key dup */
NULL, /* val dup */
dictObjKeyCompare, /* key compare */
dictObjectDestructor, /* key destructor */
dictDictDestructor, /* val destructor */
Expand All @@ -552,7 +541,6 @@ dictType objToDictDictType = {
dictType modulesDictType = {
dictSdsCaseHash, /* hash function */
NULL, /* key dup */
NULL, /* val dup */
dictSdsKeyCaseCompare, /* key compare */
dictSdsDestructor, /* key destructor */
NULL, /* val destructor */
Expand All @@ -563,7 +551,6 @@ dictType modulesDictType = {
dictType migrateCacheDictType = {
dictSdsHash, /* hash function */
NULL, /* key dup */
NULL, /* val dup */
dictSdsKeyCompare, /* key compare */
dictSdsDestructor, /* key destructor */
NULL, /* val destructor */
Expand All @@ -575,7 +562,6 @@ dictType migrateCacheDictType = {
dictType stringSetDictType = {
dictCStrCaseHash, /* hash function */
NULL, /* key dup */
NULL, /* val dup */
dictCStrKeyCaseCompare, /* key compare */
dictSdsDestructor, /* key destructor */
NULL, /* val destructor */
Expand All @@ -587,7 +573,6 @@ dictType stringSetDictType = {
dictType externalStringType = {
dictCStrCaseHash, /* hash function */
NULL, /* key dup */
NULL, /* val dup */
dictCStrKeyCaseCompare, /* key compare */
NULL, /* key destructor */
NULL, /* val destructor */
Expand All @@ -599,7 +584,6 @@ dictType externalStringType = {
dictType sdsHashDictType = {
dictSdsCaseHash, /* hash function */
NULL, /* key dup */
NULL, /* val dup */
dictSdsKeyCaseCompare, /* key compare */
dictSdsDestructor, /* key destructor */
dictVanillaFree, /* val destructor */
Expand All @@ -610,7 +594,6 @@ dictType sdsHashDictType = {
dictType clientDictType = {
dictClientHash, /* hash function */
NULL, /* key dup */
NULL, /* val dup */
dictClientKeyCompare, /* key compare */
.no_value = 1 /* no values in this dict */
};
Expand Down
1 change: 0 additions & 1 deletion src/t_zset.c
Original file line number Diff line number Diff line change
Expand Up @@ -2527,7 +2527,6 @@ static void zdiff(zsetopsrc *src, long setnum, zset *dstzset, size_t *maxelelen,
dictType setAccumulatorDictType = {
dictSdsHash, /* hash function */
NULL, /* key dup */
NULL, /* val dup */
dictSdsKeyCompare, /* key compare */
NULL, /* key destructor */
NULL, /* val destructor */
Expand Down
2 changes: 1 addition & 1 deletion src/unit/test_kvstore.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void freeTestCallback(dict *d, void *val) {
zfree(val);
}

dictType KvstoreDictTestType = {hashTestCallback, NULL, NULL, NULL, freeTestCallback, NULL, NULL};
dictType KvstoreDictTestType = {hashTestCallback, NULL, NULL, freeTestCallback, NULL, NULL};

char *stringFromInt(int value) {
char buf[32];
Expand Down
1 change: 0 additions & 1 deletion src/valkey-benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,6 @@ static int fetchClusterSlotsConfiguration(client c) {
static dictType dtype = {
dictSdsHash, /* hash function */
NULL, /* key dup */
NULL, /* val dup */
dictSdsKeyCompare, /* key compare */
NULL, /* key destructor */
NULL, /* val destructor */
Expand Down
4 changes: 0 additions & 4 deletions src/valkey-cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,6 @@ static void cliInitHelp(void) {
dictType groupsdt = {
dictSdsHash, /* hash function */
NULL, /* key dup */
NULL, /* val dup */
dictSdsKeyCompare, /* key compare */
dictSdsDestructor, /* key destructor */
NULL, /* val destructor */
Expand Down Expand Up @@ -3544,7 +3543,6 @@ typedef struct clusterManagerLink {
static dictType clusterManagerDictType = {
dictSdsHash, /* hash function */
NULL, /* key dup */
NULL, /* val dup */
dictSdsKeyCompare, /* key compare */
NULL, /* key destructor */
dictSdsDestructor, /* val destructor */
Expand All @@ -3554,7 +3552,6 @@ static dictType clusterManagerDictType = {
static dictType clusterManagerLinkDictType = {
dictSdsHash, /* hash function */
NULL, /* key dup */
NULL, /* val dup */
dictSdsKeyCompare, /* key compare */
dictSdsDestructor, /* key destructor */
dictListDestructor, /* val destructor */
Expand Down Expand Up @@ -8628,7 +8625,6 @@ void type_free(dict *d, void *val) {
static dictType typeinfoDictType = {
dictSdsHash, /* hash function */
NULL, /* key dup */
NULL, /* val dup */
dictSdsKeyCompare, /* key compare */
NULL, /* key destructor (owned by the value)*/
type_free, /* val destructor */
Expand Down

0 comments on commit 0700c44

Please sign in to comment.