Browse Source

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

That method is O(n), and should generally be avoided.
Ali Mohammad Pur 3 years ago
parent
commit
66249612d6
1 changed files with 3 additions and 3 deletions
  1. 3 3
      Userland/Libraries/LibRegex/RegexByteCode.cpp

+ 3 - 3
Userland/Libraries/LibRegex/RegexByteCode.cpp

@@ -186,10 +186,10 @@ ALWAYS_INLINE OpCode& ByteCode::get_opcode_by_id(OpCodeId id) const
 OpCode& ByteCode::get_opcode(MatchState& state) const
 OpCode& ByteCode::get_opcode(MatchState& state) const
 {
 {
     OpCodeId opcode_id;
     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
     else
-        opcode_id = (OpCodeId)at(state.instruction_position);
+        opcode_id = OpCodeId::Exit;
 
 
     auto& opcode = get_opcode_by_id(opcode_id);
     auto& opcode = get_opcode_by_id(opcode_id);
     opcode.set_state(state);
     opcode.set_state(state);