From 741772aef9d28e755e586e7eb6daf3025824085a Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 5 Oct 2017 09:36:40 +0800 Subject: [PATCH] Regex: Optimize single char character classes as literals --- src/regex_impl.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/regex_impl.cc b/src/regex_impl.cc index 3e6cd832..52c45d61 100644 --- a/src/regex_impl.cc +++ b/src/regex_impl.cc @@ -381,6 +381,12 @@ private: cp = to_lower(cp); } + // Optimize the relatively common case of using a character class to + // escape a character, such as [*] + if (ctypes.empty() and excluded.empty() and not negative and + ranges.size() == 1 and ranges.front().min == ranges.front().max) + return new_node(ParsedRegex::Literal, ranges.front().min); + auto matcher = [ranges = std::move(ranges), ctypes = std::move(ctypes), excluded = std::move(excluded),