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.
This commit is contained in:
sundb 2020-12-01 05:03:53 +08:00 committed by GitHub
parent d322e7baba
commit 04056b767f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;
}