From 8d892eeb6256140d6f942f61bda45a8ba99c0027 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 1 Dec 2017 15:03:03 +0800 Subject: [PATCH] Regex: use StartDesc to early out when not searching Early out as well if we do not find any potential start position. --- src/regex_impl.hh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/regex_impl.hh b/src/regex_impl.hh index 11dea98d..2615d7b0 100644 --- a/src/regex_impl.hh +++ b/src/regex_impl.hh @@ -183,8 +183,18 @@ public: const bool search = (flags & RegexExecFlags::Search); Utf8It start{m_begin}; - if (search and m_program.start_desc) - to_next_start(start, m_end, *m_program.start_desc); + if (m_program.start_desc) + { + if (search) + { + to_next_start(start, m_end, *m_program.start_desc); + if (start == m_end) // If start_desc is not null, it means we consume at least one char + return false; + } + else if (start != m_end and + not m_program.start_desc->map[std::min(*start, CompiledRegex::StartDesc::other)]) + return false; + } return exec_program(start, Thread{&m_program.instructions[search ? 0 : CompiledRegex::search_prefix_size], nullptr}); }