diff --git a/src/t_zset.c b/src/t_zset.c index 6cc93ea4d..97b2c071f 100644 --- a/src/t_zset.c +++ b/src/t_zset.c @@ -2529,15 +2529,6 @@ static void zdiff(zsetopsrc *src, long setnum, zset *dstzset, size_t *maxelelen, } } -dictType setAccumulatorDictType = { - dictSdsHash, /* hash function */ - NULL, /* key dup */ - dictSdsKeyCompare, /* key compare */ - NULL, /* key destructor */ - NULL, /* val destructor */ - NULL /* allow to expand */ -}; - /* The zunionInterDiffGenericCommand() function is called in order to implement the * following commands: ZUNION, ZINTER, ZDIFF, ZUNIONSTORE, ZINTERSTORE, ZDIFFSTORE, * ZINTERCARD. @@ -2724,7 +2715,6 @@ void zunionInterDiffGenericCommand(client *c, robj *dstkey, int numkeysIndex, in zuiClearIterator(&src[0]); } } else if (op == SET_OP_UNION) { - dict *accumulator = dictCreate(&setAccumulatorDictType); dictIterator *di; dictEntry *de, *existing; double score; @@ -2732,7 +2722,7 @@ void zunionInterDiffGenericCommand(client *c, robj *dstkey, int numkeysIndex, in if (setnum) { /* Our union is at least as large as the largest set. * Resize the dictionary ASAP to avoid useless rehashing. */ - dictExpand(accumulator, zuiLength(&src[setnum - 1])); + dictExpand(dstzset->dict, zuiLength(&src[setnum - 1])); } /* Step 1: Create a dictionary of elements -> aggregated-scores @@ -2747,7 +2737,7 @@ void zunionInterDiffGenericCommand(client *c, robj *dstkey, int numkeysIndex, in if (isnan(score)) score = 0; /* Search for this element in the accumulating dictionary. */ - de = dictAddRaw(accumulator, zuiSdsFromValue(&zval), &existing); + de = dictAddRaw(dstzset->dict, zuiSdsFromValue(&zval), &existing); /* If we don't have it, we need to create a new entry. */ if (!existing) { tmp = zuiNewSdsFromValue(&zval); @@ -2757,7 +2747,7 @@ void zunionInterDiffGenericCommand(client *c, robj *dstkey, int numkeysIndex, in totelelen += sdslen(tmp); if (sdslen(tmp) > maxelelen) maxelelen = sdslen(tmp); /* Update the element with its initial score. */ - dictSetKey(accumulator, de, tmp); + dictSetKey(dstzset->dict, de, tmp); dictSetDoubleVal(de, score); } else { /* Update the score with the score of the new instance @@ -2774,21 +2764,15 @@ void zunionInterDiffGenericCommand(client *c, robj *dstkey, int numkeysIndex, in } /* Step 2: convert the dictionary into the final sorted set. */ - di = dictGetIterator(accumulator); - - /* We now are aware of the final size of the resulting sorted set, - * let's resize the dictionary embedded inside the sorted set to the - * right size, in order to save rehashing time. */ - dictExpand(dstzset->dict, dictSize(accumulator)); + di = dictGetIterator(dstzset->dict); while ((de = dictNext(di)) != NULL) { sds ele = dictGetKey(de); score = dictGetDoubleVal(de); znode = zslInsert(dstzset->zsl, score, ele); - dictAdd(dstzset->dict, ele, &znode->score); + dictSetVal(dstzset->dict, de, &znode->score); } dictReleaseIterator(di); - dictRelease(accumulator); } else if (op == SET_OP_DIFF) { zdiff(src, setnum, dstzset, &maxelelen, &totelelen); } else {