1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 04:07:44 +00:00

LibRegex: Only skip full instructions when optimizing alternations

It makes no sense to skip half of an instruction, so make sure to skip
only full instructions!
This commit is contained in:
Ali Mohammad Pur 2022-02-09 23:43:09 +03:30 committed by Linus Groh
parent f0d2489254
commit 6a4c8a66ae
2 changed files with 8 additions and 1 deletions

View file

@ -484,7 +484,12 @@ void Optimizer::append_alternation(ByteCode& target, ByteCode&& left, ByteCode&&
if (left.spans().slice(left_block.start, left_end - left_block.start) != right.spans().slice(right_block.start, right_end - right_block.start))
break;
left_skip = left_end;
state.instruction_position = 0;
while (state.instruction_position < left_end) {
auto& opcode = left.get_opcode(state);
left_skip = state.instruction_position;
state.instruction_position += opcode.size();
}
}
dbgln_if(REGEX_DEBUG, "Skipping {}/{} bytecode entries from {}/{}", left_skip, 0, left.size(), right.size());