1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:48:11 +00:00

LibRegex: Avoid calling DisjointChunks::size() in get_opcode()

That method is O(n), and should generally be avoided.
This commit is contained in:
Ali Mohammad Pur 2021-12-21 18:07:04 +03:30 committed by Andreas Kling
parent 49cbd4dcca
commit 66249612d6

View file

@ -186,10 +186,10 @@ ALWAYS_INLINE OpCode& ByteCode::get_opcode_by_id(OpCodeId id) const
OpCode& ByteCode::get_opcode(MatchState& state) const
{
OpCodeId opcode_id;
if (state.instruction_position >= size())
opcode_id = OpCodeId::Exit;
if (auto opcode_ptr = static_cast<DisjointChunks<ByteCodeValueType> const&>(*this).find(state.instruction_position))
opcode_id = (OpCodeId)*opcode_ptr;
else
opcode_id = (OpCodeId)at(state.instruction_position);
opcode_id = OpCodeId::Exit;
auto& opcode = get_opcode_by_id(opcode_id);
opcode.set_state(state);