Skip to content

Commit f2f7bf8

Browse files
committed
Improve readability and efficiency for ZUNION operation.
Signed-off-by: Qu Chen <[email protected]>
1 parent b3b4bdc commit f2f7bf8

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/t_zset.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -2793,7 +2793,7 @@ void zunionInterDiffGenericCommand(client *c, robj *dstkey, int numkeysIndex, in
27932793
if (isnan(score)) score = 0;
27942794

27952795
/* Search for this element in the accumulating dictionary. */
2796-
de = dictAddRaw(dstzset->dict, zuiSdsFromValue(&zval), &existing);
2796+
existing = dictFind(dstzset->dict, zuiSdsFromValue(&zval));
27972797
/* If we don't have it, we need to create a new entry. */
27982798
if (!existing) {
27992799
tmp = zuiNewSdsFromValue(&zval);
@@ -2802,8 +2802,8 @@ void zunionInterDiffGenericCommand(client *c, robj *dstkey, int numkeysIndex, in
28022802
* at the end. */
28032803
totelelen += sdslen(tmp);
28042804
if (sdslen(tmp) > maxelelen) maxelelen = sdslen(tmp);
2805-
/* Update the element with its initial score. */
2806-
dictSetKey(dstzset->dict, de, tmp);
2805+
/* Insert the element with its initial score. */
2806+
de = dictAddRaw(dstzset->dict, tmp, NULL);
28072807
dictSetDoubleVal(de, score);
28082808
} else {
28092809
/* Update the score with the score of the new instance

0 commit comments

Comments
 (0)