summaryrefslogtreecommitdiff
path: root/src/regex_impl.hh
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2024-12-05 22:48:09 +1100
committerMaxime Coste <mawww@kakoune.org>2025-01-22 08:18:32 +1100
commitd92496449d0c9655253ad16363685bb8446dc582 (patch)
treec539b0b66a1e2c6da8f6a0c11e17f700a46ee0c8 /src/regex_impl.hh
parent2856b99e0914cc7a659977f2b33308cb5b4c9bb7 (diff)
Use uint64_t for regex step
Its unclear that maintaining a small instruction size outweigh the cost of handling wrapping of the current_step every 64K codepoints, this makes the code simpler.
Diffstat (limited to 'src/regex_impl.hh')
-rw-r--r--src/regex_impl.hh33
1 files changed, 9 insertions, 24 deletions
diff --git a/src/regex_impl.hh b/src/regex_impl.hh
index b04d99e7..8dc1bc10 100644
--- a/src/regex_impl.hh
+++ b/src/regex_impl.hh
@@ -130,12 +130,9 @@ struct CompiledRegex : UseMemoryDomain<MemoryDomain::Regex>
struct Instruction
{
Op op;
- mutable uint16_t last_step; // mutable as used during execution
Param param;
+ mutable uint64_t last_step; // mutable as used during execution
};
-#ifndef __ppc__
- static_assert(sizeof(Instruction) == 8);
-#endif
explicit operator bool() const { return not instructions.empty(); }
@@ -358,7 +355,7 @@ private:
// Steps a thread until it consumes the current character, matches or fail
[[gnu::always_inline]]
- void step_current_thread(const Iterator& pos, Codepoint cp, uint16_t current_step, const ExecConfig& config)
+ void step_current_thread(const Iterator& pos, Codepoint cp, uint64_t current_step, const ExecConfig& config)
{
Thread thread = m_threads.pop_current();
auto failed = [this, &thread]() {
@@ -482,23 +479,17 @@ private:
const auto insts = forward ? ArrayView(m_program.instructions).subrange(0, m_program.first_backward_inst)
: ArrayView(m_program.instructions).subrange(m_program.first_backward_inst);
+ for (auto& inst : insts)
+ inst.last_step = 0;
m_threads.push_current({insts.begin(), -1});
- uint16_t current_step = -1;
- uint8_t idle_count = 0; // Run idle loop every 256 * 65536 == 16M codepoints
+ constexpr uint64_t idle_frequency = 256 * 65536;
+ uint64_t current_step = 0;
Iterator pos = next_start;
while (pos != config.end)
{
- if (++current_step == 0)
- {
- if (++idle_count == 0)
- idle_func();
-
- // We wrapped, avoid potential collision on inst.last_step by resetting them
- for (auto& inst : insts)
- inst.last_step = 0;
- current_step = 1; // step 0 is never valid
- }
+ if ((++current_step % idle_frequency) == 0)
+ idle_func();
auto next = pos;
Codepoint cp = codepoint(next, config);
@@ -525,14 +516,8 @@ private:
m_threads.swap_next();
}
- if (++current_step == 0)
- {
- for (auto& inst : insts)
- inst.last_step = 0;
- current_step = 1; // step 0 is never valid
- }
while (not m_threads.current_is_empty())
- step_current_thread(pos, -1, current_step, config);
+ step_current_thread(pos, -1, -1, config);
}
static Iterator find_next_start(const Iterator& start, const Sentinel& end, const StartDesc& start_desc)