Optimize SDIFF to return as soon as the result set is empty

This commit is contained in:
Aman Gupta 2009-05-17 12:25:05 -07:00
parent f4f56e1dfb
commit 51829ed3f0
1 changed files with 3 additions and 0 deletions

View File

@ -3112,6 +3112,7 @@ static void sunionDiffGenericCommand(redisClient *c, robj **setskeys, int setsnu
/* Iterate all the elements of all the sets, add every element a single
* time to the result set */
for (j = 0; j < setsnum; j++) {
if (op == REDIS_OP_DIFF && j == 0 && !dv[j]) break; /* result set is empty */
if (!dv[j]) continue; /* non existing keys are like empty sets */
di = dictGetIterator(dv[j]);
@ -3134,6 +3135,8 @@ static void sunionDiffGenericCommand(redisClient *c, robj **setskeys, int setsnu
}
}
dictReleaseIterator(di);
if (op == REDIS_OP_DIFF && cardinality == 0) break; /* result set is empty */
}
/* Output the content of the resulting set, if not in STORE mode */