Optimize repeated keyname hashing.

(Change cherry-picked and modified by @antirez from a larger commit
provided by @oranagra in PR #3223).
This commit is contained in:
oranagra
2016-05-09 18:01:09 +03:00
committed by antirez
parent d680eb6dbd
commit 68bf45fa1e
5 changed files with 56 additions and 59 deletions

View File

@ -3640,15 +3640,15 @@ struct sentinelLeader {
/* Helper function for sentinelGetLeader, increment the counter
* relative to the specified runid. */
int sentinelLeaderIncr(dict *counters, char *runid) {
dictEntry *de = dictFind(counters,runid);
dictEntry *existing, *de;
uint64_t oldval;
if (de) {
oldval = dictGetUnsignedIntegerVal(de);
dictSetUnsignedIntegerVal(de,oldval+1);
de = dictAddRaw(counters,runid,&existing);
if (existing) {
oldval = dictGetUnsignedIntegerVal(existing);
dictSetUnsignedIntegerVal(existing,oldval+1);
return oldval+1;
} else {
de = dictAddRaw(counters,runid);
serverAssert(de != NULL);
dictSetUnsignedIntegerVal(de,1);
return 1;