Improve readability and efficiency for ZUNION operation #1506
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently zunion operation in
t_zset.c
is usingdictAddRaw()
to search for the element in the accumulating dictionary. If the element was not found and got added, it would then set the key to a new key string viadictSetKey()
, which is counter intuitive and not very effective.This PR improves the code readability and effectiveness by using
dictFind()
to search for the element in the dictionary, and then usesdictAddRaw()
anddictSetDoubleVal()
to create the element in the set, and avoids the need to calldictSetKey()
.Note - this change is consistent with the original implementation of sorted set
valkey/src/t_zset.c
Line 2286 in d680eb6