diff --git a/benchmarks/src/regex_search.cpp b/benchmarks/src/regex_search.cpp index 9fd341db64..013a101712 100644 --- a/benchmarks/src/regex_search.cpp +++ b/benchmarks/src/regex_search.cpp @@ -47,5 +47,8 @@ BENCHMARK_CAPTURE(bm_lorem_search, R"(\Bibe)", R"(\Bibe)")->Apply(common_args); BENCHMARK_CAPTURE(bm_lorem_search, R"((?=....)bibe)", R"((?=....)bibe)")->Apply(common_args); BENCHMARK_CAPTURE(bm_lorem_search, R"((?=bibe)....)", R"((?=bibe)....)")->Apply(common_args); BENCHMARK_CAPTURE(bm_lorem_search, R"((?!lorem)bibe)", R"((?!lorem)bibe)")->Apply(common_args); +BENCHMARK_CAPTURE(bm_lorem_search, "(bibe|soda)", "(bibe|soda)")->Apply(common_args); +BENCHMARK_CAPTURE(bm_lorem_search, "(id )?bibe", "(id )?bibe")->Apply(common_args); +BENCHMARK_CAPTURE(bm_lorem_search, ".bibe", ".bibe")->Apply(common_args); BENCHMARK_MAIN(); diff --git a/stl/inc/regex b/stl/inc/regex index a23aac9f8e..497b80b349 100644 --- a/stl/inc/regex +++ b/stl/inc/regex @@ -5015,13 +5015,22 @@ _It _Matcher3<_Elem, _RxTraits, _It, _Alloc>::_Skip( return _First; } + case _N_dot: + { + if (_Recursion_depth >= _Max_recursion_depth) { + return _First; + } + + _First = _Skip(++_First, _Last, _Nx->_Next, _Recursion_depth + 1U); + return --_First; + } + case _N_begin: case _N_endif: break; case _N_end: case _N_none: - case _N_dot: case _N_back: case _N_end_rep: default: diff --git a/tests/std/tests/VSO_0000000_regex_use/test.cpp b/tests/std/tests/VSO_0000000_regex_use/test.cpp index c4ea150e96..a01f4822a9 100644 --- a/tests/std/tests/VSO_0000000_regex_use/test.cpp +++ b/tests/std/tests/VSO_0000000_regex_use/test.cpp @@ -2507,6 +2507,21 @@ void test_gh_6181() { } } +void test_gh_6189() { + // GH-6189: Optimize skip heuristic for searches of patterns with initial dot wildcards + test_regex re(&g_regexTester, ".abc"); + re.should_search_match("dabc", "dabc"); + re.should_search_match("dabcdddd", "dabc"); + re.should_search_match("ddabc", "dabc"); + re.should_search_match("ddabcdddd", "dabc"); + re.should_search_match("ddddddddddddddddabcdddddddddddd", "dabc"); + re.should_search_match("ddddddddddddddddddddddddabc", "dabc"); + re.should_search_match("ddabcddd", "dabc"); + re.should_search_fail("abcddddd"); + re.should_search_fail("ddddddddddd\nabcdddddddddd"); + re.should_search_fail("d"); +} + int main() { test_dev10_449367_case_insensitivity_should_work(); test_dev11_462743_regex_collate_should_not_disable_regex_icase(); @@ -2572,6 +2587,7 @@ int main() { test_gh_6118(); test_gh_6147(); test_gh_6181(); + test_gh_6189(); return g_regexTester.result(); }