Regex: detect when all characters can start and avoid allocating

This commit is contained in:
Maxime Coste 2017-10-08 12:22:52 +08:00
parent ea85f79384
commit 34b1f1ccb6

View File

@ -769,6 +769,9 @@ private:
if (compute_start_chars(m_parsed_regex.ast, accepted, rejected)) if (compute_start_chars(m_parsed_regex.ast, accepted, rejected))
return nullptr; return nullptr;
if (not contains(accepted, false) and not contains(rejected, true))
return nullptr;
auto start_chars = std::make_unique<CompiledRegex::StartChars>(); auto start_chars = std::make_unique<CompiledRegex::StartChars>();
for (int i = 0; i < 256; ++i) for (int i = 0; i < 256; ++i)
start_chars->map[i] = accepted[i] and not rejected[i]; start_chars->map[i] = accepted[i] and not rejected[i];