From: Aman Gupta Date: Sun, 17 May 2009 19:25:05 +0000 (-0700) Subject: Optimize SDIFF to return as soon as the result set is empty X-Git-Url: https://git.saurik.com/redis.git/commitdiff_plain/51829ed3f09bb4381f075900521bcaafee8819bb Optimize SDIFF to return as soon as the result set is empty --- diff --git a/redis.c b/redis.c index 6be82b4b..a3341f6d 100644 --- a/redis.c +++ b/redis.c @@ -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 */