From c1f0efa3f424317a85ede4100136caf7d330f8e2 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 30 Nov 2017 14:19:41 +0800 Subject: [PATCH] Regex: smarter handling of start chars computation for character class --- src/regex_impl.cc | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/regex_impl.cc b/src/regex_impl.cc index cb762e4e..80243608 100644 --- a/src/regex_impl.cc +++ b/src/regex_impl.cc @@ -891,10 +891,23 @@ private: case ParsedRegex::Class: { auto& character_class = m_parsed_regex.character_classes[node.value]; - for (Codepoint cp = 0; cp < CompiledRegex::StartChars::count; ++cp) + if (character_class.ctypes == CharacterType::None and not character_class.negative) { - if (is_character_class(character_class, cp)) - start_chars.map[cp] = true; + for (auto& range : character_class.ranges) + { + auto min = std::min(CompiledRegex::StartChars::other, range.min); + auto max = std::min(CompiledRegex::StartChars::other, range.max); + for (Codepoint cp = min; cp <= max; ++cp) + start_chars.map[cp] = true; + } + } + else + { + for (Codepoint cp = 0; cp < CompiledRegex::StartChars::other; ++cp) + { + if (start_chars.map[cp] or is_character_class(character_class, cp)) + start_chars.map[cp] = true; + } } start_chars.map[CompiledRegex::StartChars::other] = true; return node.quantifier.allows_none();