summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2025-02-04 19:21:43 +1100
committerMaxime Coste <mawww@kakoune.org>2025-02-04 19:21:43 +1100
commit8eb753adfd914b0deade48c7510e30f7e05df860 (patch)
treeed643f3751447ec3e65deeb228c3f826627d6174 /src
parentd92496449d0c9655253ad16363685bb8446dc582 (diff)
Revert "Use uint64_t for regex step"
This got pushed by accident This reverts commit d92496449d0c9655253ad16363685bb8446dc582.
Diffstat (limited to 'src')
-rw-r--r--src/regex_impl.cc2
-rw-r--r--src/regex_impl.hh33
2 files changed, 25 insertions, 10 deletions
diff --git a/src/regex_impl.cc b/src/regex_impl.cc
index 6ac9b4f2..0789ef6d 100644
--- a/src/regex_impl.cc
+++ b/src/regex_impl.cc
@@ -867,7 +867,7 @@ private:
const auto res = op_count();
if (res >= max_instructions)
throw regex_error(format("regex compiled to more than {} instructions", max_instructions));
- m_program.instructions.push_back({ op, param, 0 });
+ m_program.instructions.push_back({ op, 0, param });
return OpIndex(res);
}
diff --git a/src/regex_impl.hh b/src/regex_impl.hh
index 8dc1bc10..b04d99e7 100644
--- a/src/regex_impl.hh
+++ b/src/regex_impl.hh
@@ -130,9 +130,12 @@ 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(); }
@@ -355,7 +358,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, uint64_t current_step, const ExecConfig& config)
+ void step_current_thread(const Iterator& pos, Codepoint cp, uint16_t current_step, const ExecConfig& config)
{
Thread thread = m_threads.pop_current();
auto failed = [this, &thread]() {
@@ -479,17 +482,23 @@ 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});
- constexpr uint64_t idle_frequency = 256 * 65536;
- uint64_t current_step = 0;
+ uint16_t current_step = -1;
+ uint8_t idle_count = 0; // Run idle loop every 256 * 65536 == 16M codepoints
Iterator pos = next_start;
while (pos != config.end)
{
- if ((++current_step % idle_frequency) == 0)
- idle_func();
+ 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
+ }
auto next = pos;
Codepoint cp = codepoint(next, config);
@@ -516,8 +525,14 @@ 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, -1, config);
+ step_current_thread(pos, -1, current_step, config);
}
static Iterator find_next_start(const Iterator& start, const Sentinel& end, const StartDesc& start_desc)