From 6e0275e5507fcb18443618bf4e27aa06ba7b4d1a Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sat, 21 Oct 2017 10:30:35 +0800 Subject: [PATCH] Regex: small code cleanup in the Save compilation code --- src/regex_impl.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/regex_impl.cc b/src/regex_impl.cc index ed17d0de..e640add5 100644 --- a/src/regex_impl.cc +++ b/src/regex_impl.cc @@ -634,9 +634,10 @@ private: const auto start_pos = m_program.instructions.size(); const bool ignore_case = node->ignore_case; - const Codepoint capture = (node->op == ParsedRegex::Alternation or node->op == ParsedRegex::Sequence) ? node->value : -1; - if (capture != -1 and (capture == 0 or not (m_flags & RegexCompileFlags::NoSubs))) - push_inst(CompiledRegex::Save, capture * 2 + (m_forward ? 0 : 1)); + const bool save = (node->op == ParsedRegex::Alternation or node->op == ParsedRegex::Sequence) and + (node->value == 0 or (node->value != -1 and not (m_flags & RegexCompileFlags::NoSubs))); + if (save) + push_inst(CompiledRegex::Save, node->value * 2 + (m_forward ? 0 : 1)); Vector goto_inner_end_offsets; switch (node->op) @@ -743,8 +744,8 @@ private: for (auto& offset : goto_inner_end_offsets) m_program.instructions[offset].param = m_program.instructions.size(); - if (capture != -1 and (capture == 0 or not (m_flags & RegexCompileFlags::NoSubs))) - push_inst(CompiledRegex::Save, capture * 2 + (m_forward ? 1 : 0)); + if (save) + push_inst(CompiledRegex::Save, node->value * 2 + (m_forward ? 1 : 0)); return start_pos; }