summaryrefslogtreecommitdiff
path: root/src/bitops.c
diff options
context:
space:
mode:
authorsundb <sundbcn@gmail.com>2020-12-01 05:03:53 +0800
committerGitHub <noreply@github.com>2020-11-30 23:03:53 +0200
commit04056b767fbcdc1df6fc536467234c04d88bee9d (patch)
treee5162c29c64f86bdc08c9df69b1143237eef45f3 /src/bitops.c
parentd322e7baba3065eb3ff03ca90e4a9a4484aaa3a7 (diff)
downloadredis-04056b767fbcdc1df6fc536467234c04d88bee9d.tar.gz
BITOP speedup when or/and output is 0/255, stop processing further keys (#8110)
when performing the and operation, if the output is 0, we can jump out of the loop. when performing an or operation, if the output is 0xff, we can jump out of the loop.
Diffstat (limited to 'src/bitops.c')
-rw-r--r--src/bitops.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/bitops.c b/src/bitops.c
index 5550b60d1..5e996679b 100644
--- a/src/bitops.c
+++ b/src/bitops.c
@@ -735,12 +735,23 @@ void bitopCommand(client *c) {
output = (len[0] <= j) ? 0 : src[0][j];
if (op == BITOP_NOT) output = ~output;
for (i = 1; i < numkeys; i++) {
+ int skip = 0;
byte = (len[i] <= j) ? 0 : src[i][j];
switch(op) {
- case BITOP_AND: output &= byte; break;
- case BITOP_OR: output |= byte; break;
+ case BITOP_AND:
+ output &= byte;
+ skip = (output == 0);
+ break;
+ case BITOP_OR:
+ output |= byte;
+ skip = (output == 0xff);
+ break;
case BITOP_XOR: output ^= byte; break;
}
+
+ if (skip) {
+ break;
+ }
}
res[j] = output;
}