mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-25 20:22:18 +03:00
LibRegex: Always inline get_opcode()
This function's prologue was showing up as very hot in profiles, taking almost 9% of runtime in our Regex test suite.
This commit is contained in:
parent
a539c261b1
commit
11abca421a
Notes:
sideshowbarker
2024-07-17 07:35:03 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/11abca421a Pull-request: https://github.com/SerenityOS/serenity/pull/20240 Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/trflynn89
@ -181,28 +181,6 @@ void ByteCode::ensure_opcodes_initialized()
|
||||
s_opcodes_initialized = true;
|
||||
}
|
||||
|
||||
ALWAYS_INLINE OpCode& ByteCode::get_opcode_by_id(OpCodeId id) const
|
||||
{
|
||||
VERIFY(id >= OpCodeId::First && id <= OpCodeId::Last);
|
||||
|
||||
auto& opcode = s_opcodes[(u32)id];
|
||||
opcode->set_bytecode(*const_cast<ByteCode*>(this));
|
||||
return *opcode;
|
||||
}
|
||||
|
||||
OpCode& ByteCode::get_opcode(MatchState& state) const
|
||||
{
|
||||
OpCodeId opcode_id;
|
||||
if (auto opcode_ptr = static_cast<DisjointChunks<ByteCodeValueType> const&>(*this).find(state.instruction_position))
|
||||
opcode_id = (OpCodeId)*opcode_ptr;
|
||||
else
|
||||
opcode_id = OpCodeId::Exit;
|
||||
|
||||
auto& opcode = get_opcode_by_id(opcode_id);
|
||||
opcode.set_state(state);
|
||||
return opcode;
|
||||
}
|
||||
|
||||
ALWAYS_INLINE ExecutionResult OpCode_Exit::execute(MatchInput const& input, MatchState& state) const
|
||||
{
|
||||
if (state.string_position > input.view.length() || state.instruction_position >= m_bytecode->size())
|
||||
|
@ -822,6 +822,28 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
ALWAYS_INLINE OpCode& ByteCode::get_opcode(regex::MatchState& state) const
|
||||
{
|
||||
OpCodeId opcode_id;
|
||||
if (auto opcode_ptr = static_cast<DisjointChunks<ByteCodeValueType> const&>(*this).find(state.instruction_position))
|
||||
opcode_id = (OpCodeId)*opcode_ptr;
|
||||
else
|
||||
opcode_id = OpCodeId::Exit;
|
||||
|
||||
auto& opcode = get_opcode_by_id(opcode_id);
|
||||
opcode.set_state(state);
|
||||
return opcode;
|
||||
}
|
||||
|
||||
ALWAYS_INLINE OpCode& ByteCode::get_opcode_by_id(OpCodeId id) const
|
||||
{
|
||||
VERIFY(id >= OpCodeId::First && id <= OpCodeId::Last);
|
||||
|
||||
auto& opcode = s_opcodes[(u32)id];
|
||||
opcode->set_bytecode(*const_cast<ByteCode*>(this));
|
||||
return *opcode;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool is(OpCode const&);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user