diff --git a/src/regex_impl.cc b/src/regex_impl.cc index 993119b91..ed17d0de3 100644 --- a/src/regex_impl.cc +++ b/src/regex_impl.cc @@ -14,6 +14,8 @@ namespace Kakoune { +constexpr Codepoint CompiledRegex::StartChars::other; + struct ParsedRegex { enum Op : char @@ -837,8 +839,6 @@ private: return res; } - static constexpr size_t start_chars_count = CompiledRegex::StartChars::count; - // Fills accepted and rejected according to which chars can start the given node, // returns true if the node did not consume the char, hence a following node in // sequence would be still relevant for the parent node start chars computation. @@ -848,7 +848,7 @@ private: switch (node->op) { case ParsedRegex::Literal: - if (node->value < start_chars_count) + if (node->value < CompiledRegex::StartChars::count) { if (node->ignore_case) { @@ -859,18 +859,18 @@ private: start_chars.map[node->value] = true; } else - start_chars.accept_other = true; + start_chars.map[CompiledRegex::StartChars::other] = true; return node->quantifier.allows_none(); case ParsedRegex::AnyChar: for (auto& b : start_chars.map) b = true; - start_chars.accept_other = true; + start_chars.map[CompiledRegex::StartChars::other] = true; return node->quantifier.allows_none(); case ParsedRegex::Matcher: - for (Codepoint c = 0; c < start_chars_count; ++c) + for (Codepoint c = 0; c < CompiledRegex::StartChars::count; ++c) if (m_program.matchers[node->value](c)) start_chars.map[c] = true; - start_chars.accept_other = true; // stay safe + start_chars.map[CompiledRegex::StartChars::other] = true; // stay safe return node->quantifier.allows_none(); case ParsedRegex::Sequence: { diff --git a/src/regex_impl.hh b/src/regex_impl.hh index 38520f3c4..5ee1b24b1 100644 --- a/src/regex_impl.hh +++ b/src/regex_impl.hh @@ -76,9 +76,10 @@ struct CompiledRegex : RefCountable, UseMemoryDomain struct StartChars { static constexpr size_t count = 256; - bool accept_other; - bool map[count]; + static constexpr Codepoint other = 256; + bool map[count+1]; }; + std::unique_ptr start_chars; }; @@ -437,8 +438,7 @@ private: return; while (start != end and *start >= 0 and - ((*start < 256 and not start_chars->map[*start]) or - (*start >= 256 and not start_chars->accept_other))) + not start_chars->map[std::min(*start, CompiledRegex::StartChars::other)]) ++start; }