diff options
| author | Maxime Coste <mawww@kakoune.org> | 2019-01-05 18:28:56 +1100 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2019-01-20 22:59:28 +1100 |
| commit | 0364a998273cdf91904a6cd6d1cf921e44b41c84 (patch) | |
| tree | 2377737484b5fb9b3403442f810c50225ebb03a0 /src/regex_impl.cc | |
| parent | fd043435e5274a138b66c9f35455c896aaeaa96e (diff) | |
Refactor regex find next start not to be an instruction anymore
The same logic can be hard coded, avoiding one thread and 3
instructions, improving the regex matching speed.
Diffstat (limited to 'src/regex_impl.cc')
| -rw-r--r-- | src/regex_impl.cc | 17 |
1 files changed, 1 insertions, 16 deletions
diff --git a/src/regex_impl.cc b/src/regex_impl.cc index 6e5bee51..28d201f5 100644 --- a/src/regex_impl.cc +++ b/src/regex_impl.cc @@ -676,14 +676,13 @@ struct RegexCompiler { kak_assert(not (flags & RegexCompileFlags::NoForward) or flags & RegexCompileFlags::Backward); // Approximation of the number of instructions generated - m_program.instructions.reserve((CompiledRegex::search_prefix_size + parsed_regex.nodes.size() + 1) + m_program.instructions.reserve((parsed_regex.nodes.size() + 1) * (((flags & RegexCompileFlags::Backward) and not (flags & RegexCompileFlags::NoForward)) ? 2 : 1)); if (not (flags & RegexCompileFlags::NoForward)) { m_program.forward_start_desc = compute_start_desc<RegexMode::Forward>(); - write_search_prefix(); compile_node<RegexMode::Forward>(0); push_inst(CompiledRegex::Match); } @@ -692,7 +691,6 @@ struct RegexCompiler { m_program.first_backward_inst = m_program.instructions.size(); m_program.backward_start_desc = compute_start_desc<RegexMode::Backward>(); - write_search_prefix(); compile_node<RegexMode::Backward>(0); push_inst(CompiledRegex::Match); } @@ -866,16 +864,6 @@ private: return start_pos; } - // Add a sequence of instructions that enable searching for a match instead of checking for it - void write_search_prefix() - { - const uint32_t first_inst = m_program.instructions.size(); - push_inst(CompiledRegex::Split_PrioritizeChild, first_inst + CompiledRegex::search_prefix_size); - push_inst(CompiledRegex::FindNextStart); - push_inst(CompiledRegex::Split_PrioritizeParent, first_inst + 1); - kak_assert(m_program.instructions.size() == first_inst + CompiledRegex::search_prefix_size); - } - uint32_t push_inst(CompiledRegex::Op op, uint32_t param = 0) { constexpr auto max_instructions = std::numeric_limits<int16_t>::max(); @@ -1137,9 +1125,6 @@ String dump_regex(const CompiledRegex& program) res += format("{} ({})\n", name, str); break; } - case CompiledRegex::FindNextStart: - res += "find next start\n"; - break; case CompiledRegex::Match: res += "match\n"; } |
