diff options
| author | Maxime Coste <mawww@kakoune.org> | 2017-11-30 14:19:41 +0800 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2017-11-30 14:19:41 +0800 |
| commit | c1f0efa3f424317a85ede4100136caf7d330f8e2 (patch) | |
| tree | 578f516605f4090b1d1b3ae50fe70cc06a738c9c /src | |
| parent | 839da764e7e86c712e8383e5c593e322e09ae2d4 (diff) | |
Regex: smarter handling of start chars computation for character class
Diffstat (limited to 'src')
| -rw-r--r-- | src/regex_impl.cc | 19 |
1 files 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(); |
