From b5f01d1b63dde1b0920c5494f9e1a983be8443d3 Mon Sep 17 00:00:00 2001 From: Rain Valentine Date: Thu, 7 Nov 2024 06:29:38 +0000 Subject: [PATCH] rebase update to use two phase position struct Signed-off-by: Rain Valentine --- src/t_set.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/t_set.c b/src/t_set.c index 1c066e7008..efc3609d0b 100644 --- a/src/t_set.c +++ b/src/t_set.c @@ -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);