summaryrefslogtreecommitdiff
path: root/src/regex_impl.hh
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2024-03-15 22:03:52 +1100
committerMaxime Coste <mawww@kakoune.org>2024-03-15 22:03:52 +1100
commitf6762724ea1c747e803c3ed8269b35dac64b41a9 (patch)
treeeec37b480dd35c8e166f5a3b80f9902bf0cf28c6 /src/regex_impl.hh
parent24d719bf13473f6c3ebd0a5ef8d2296954ca38ab (diff)
Revert "Always allocate saves"
This crashes in unit tests This reverts commit cde5f5a25838b2c9a2bf198b819a58d723b434a3.
Diffstat (limited to 'src/regex_impl.hh')
-rw-r--r--src/regex_impl.hh25
1 files changed, 11 insertions, 14 deletions
diff --git a/src/regex_impl.hh b/src/regex_impl.hh
index b18fe9a4..3f0d5850 100644
--- a/src/regex_impl.hh
+++ b/src/regex_impl.hh
@@ -313,10 +313,8 @@ private:
template<bool copy>
int16_t new_saves(Iterator* pos, uint32_t valid_mask)
{
- if constexpr (mode & RegexMode::NoSaves)
- return -1;
-
kak_assert(not copy or pos != nullptr);
+ const auto count = m_program.save_count;
if (m_first_free >= 0)
{
const int16_t res = m_first_free;
@@ -329,7 +327,6 @@ private:
return res;
}
- const auto count = m_program.save_count;
auto* new_pos = reinterpret_cast<Iterator*>(operator new (count * sizeof(Iterator)));
for (size_t i = 0; i < count; ++i)
new (new_pos+i) Iterator{copy ? pos[i] : Iterator{}};
@@ -339,9 +336,8 @@ private:
void release_saves(int16_t index)
{
- if constexpr (mode & RegexMode::NoSaves)
+ if (index < 0)
return;
-
auto& saves = m_saves[index];
if (saves.refcount == 1)
{
@@ -397,8 +393,7 @@ private:
(config.flags & RegexExecFlags::NotInitialNull and pos == config.begin))
return failed();
- if (m_captures >= 0)
- release_saves(m_captures);
+ release_saves(m_captures);
m_captures = thread.saves;
m_found_match = true;
@@ -424,7 +419,8 @@ private:
if (auto target = inst.param.split.target;
instructions[target].last_step != current_step)
{
- ++m_saves[thread.saves].refcount;
+ if (thread.saves >= 0)
+ ++m_saves[thread.saves].refcount;
if (not inst.param.split.prioritize_parent)
std::swap(thread.inst, target);
m_threads.push_current({target, thread.saves});
@@ -433,7 +429,9 @@ private:
case CompiledRegex::Save:
if constexpr (mode & RegexMode::NoSaves)
break;
- if (auto& saves = m_saves[thread.saves]; saves.refcount > 1)
+ if (thread.saves < 0)
+ thread.saves = new_saves<false>(nullptr, 0);
+ else if (auto& saves = m_saves[thread.saves]; saves.refcount > 1)
{
--saves.refcount;
thread.saves = new_saves<true>(saves.pos, saves.valid_mask);
@@ -473,13 +471,12 @@ private:
bool exec_program(Iterator pos, const ExecConfig& config, auto&& idle_func)
{
kak_assert(m_threads.current_is_empty() and m_threads.next_is_empty());
- if (m_captures >= 0)
- release_saves(m_captures);
+ release_saves(m_captures);
m_captures = -1;
m_threads.ensure_initial_capacity();
const int16_t first_inst = forward ? 0 : m_program.first_backward_inst;
- m_threads.push_current({first_inst, new_saves<false>(nullptr, 0)});
+ m_threads.push_current({first_inst, -1});
const auto& start_desc = forward ? m_program.forward_start_desc : m_program.backward_start_desc;
@@ -521,7 +518,7 @@ private:
{
if (start_desc and m_threads.next_is_empty())
to_next_start(pos, config, *start_desc);
- m_threads.push_next({first_inst, new_saves<false>(nullptr, 0)});
+ m_threads.push_next({first_inst, -1});
}
m_threads.swap_next();
}