Slight simplification of ThreadedRegexVM::exec

Remove redundant checking for end and double indirection to get
instructions pointer.
This commit is contained in:
Maxime Coste 2024-03-05 22:37:04 +11:00
parent e24b969704
commit dda908c478

View File

@ -361,7 +361,8 @@ private:
// Steps a thread until it consumes the current character, matches or fail // Steps a thread until it consumes the current character, matches or fail
[[gnu::always_inline]] [[gnu::always_inline]]
void step_thread(const Iterator& pos, Codepoint cp, uint16_t current_step, Thread thread, const ExecConfig& config) void step_thread(const CompiledRegex::Instruction* instructions, const Iterator& pos, Codepoint cp,
uint16_t current_step, Thread thread, const ExecConfig& config)
{ {
auto failed = [this, &thread]() { auto failed = [this, &thread]() {
release_saves(thread.saves); release_saves(thread.saves);
@ -370,7 +371,6 @@ private:
m_threads.push_next(thread); m_threads.push_next(thread);
}; };
auto* instructions = m_program.instructions.data();
while (true) while (true)
{ {
auto& inst = instructions[thread.inst++]; auto& inst = instructions[thread.inst++];
@ -479,6 +479,7 @@ private:
constexpr bool search = mode & RegexMode::Search; constexpr bool search = mode & RegexMode::Search;
constexpr bool any_match = mode & RegexMode::AnyMatch; constexpr bool any_match = mode & RegexMode::AnyMatch;
ConstArrayView<CompiledRegex::Instruction> insts{m_program.instructions};
uint16_t current_step = -1; uint16_t current_step = -1;
m_found_match = false; m_found_match = false;
while (true) // Iterate on all codepoints and once at the end while (true) // Iterate on all codepoints and once at the end
@ -488,20 +489,17 @@ private:
idle_func(); idle_func();
// We wrapped, avoid potential collision on inst.last_step by resetting them // We wrapped, avoid potential collision on inst.last_step by resetting them
ConstArrayView<CompiledRegex::Instruction> instructions{m_program.instructions}; for (auto& inst : forward ? insts.subrange(0, m_program.first_backward_inst)
instructions = forward ? instructions.subrange(0, m_program.first_backward_inst) : insts.subrange(m_program.first_backward_inst))
: instructions.subrange(m_program.first_backward_inst);
for (auto& inst : instructions)
inst.last_step = 0; inst.last_step = 0;
current_step = 1; // step 0 is never valid current_step = 1; // step 0 is never valid
} }
auto next = pos; auto next = pos;
Codepoint cp = pos != config.end ? codepoint(next, config) : -1; Codepoint cp = codepoint(next, config);
while (not m_threads.current_is_empty()) while (not m_threads.current_is_empty())
step_thread(pos, cp, current_step, m_threads.pop_current(), config); step_thread(insts.pointer(), pos, cp, current_step, m_threads.pop_current(), config);
if (pos == config.end or if (pos == config.end or
(m_threads.next_is_empty() and (not search or m_found_match)) or (m_threads.next_is_empty() and (not search or m_found_match)) or