Skip to content

Commit

Permalink
rebase update to use two phase position struct
Browse files Browse the repository at this point in the history
Signed-off-by: Rain Valentine <[email protected]>
  • Loading branch information
SoftlyRaining committed Nov 7, 2024
1 parent 94defd4 commit b5f01d1
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/t_set.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,17 @@ int setTypeAddAux(robj *set, char *str, size_t len, int64_t llval, int str_is_sd
/* Avoid duping the string if it is an sds string. */
sds sdsval = str_is_sds ? (sds)str : sdsnewlen(str, len);
hashset *hs = set->ptr;
void *position = hashsetFindPositionForInsert(hs, sdsval, NULL);
if (position) {
hashsetPosition position;
if (hashsetFindPositionForInsert(hs, sdsval, &position, NULL)) {
/* Key doesn't already exist in the set. Add it but dup the key. */
if (sdsval == str) sdsval = sdsdup(sdsval);
hashsetInsertAtPosition(hs, sdsval, position);
hashsetInsertAtPosition(hs, sdsval, &position);
return 1;
} else if (sdsval != str) {
/* String is already a member. Free our temporary sds copy. */
sdsfree(sdsval);
return 0;
}
return (position != NULL);
} else if (set->encoding == OBJ_ENCODING_LISTPACK) {
unsigned char *lp = set->ptr;
unsigned char *p = lpFirst(lp);
Expand Down

0 comments on commit b5f01d1

Please sign in to comment.