Unverified Commit 04056b76 authored by sundb's avatar sundb Committed by GitHub
Browse files

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.
parent d322e7ba
...@@ -735,12 +735,23 @@ void bitopCommand(client *c) { ...@@ -735,12 +735,23 @@ void bitopCommand(client *c) {
output = (len[0] <= j) ? 0 : src[0][j]; output = (len[0] <= j) ? 0 : src[0][j];
if (op == BITOP_NOT) output = ~output; if (op == BITOP_NOT) output = ~output;
for (i = 1; i < numkeys; i++) { for (i = 1; i < numkeys; i++) {
int skip = 0;
byte = (len[i] <= j) ? 0 : src[i][j]; byte = (len[i] <= j) ? 0 : src[i][j];
switch(op) { switch(op) {
case BITOP_AND: output &= byte; break; case BITOP_AND:
case BITOP_OR: output |= byte; break; output &= byte;
skip = (output == 0);
break;
case BITOP_OR:
output |= byte;
skip = (output == 0xff);
break;
case BITOP_XOR: output ^= byte; break; case BITOP_XOR: output ^= byte; break;
} }
if (skip) {
break;
}
} }
res[j] = output; res[j] = output;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment