https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88947
--- Comment #10 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Tamar Christina <[email protected]>: https://gcc.gnu.org/g:ded7c4e851228c008304bad10d6b0aedc9deef3b commit r17-4554-gded7c4e851228c008304bad10d6b0aedc9deef3b Author: Tamar Christina <[email protected]> Date: Tue Sep 22 07:22:45 2026 +0100 libstdc++: Reject impossible regex DFS starts early [PR126274] This patch add a conservative first-character precheck for DFS prefix search. regex_search and regex_token_iterator try the pattern at each possible input position. However for many regexp some of those positions can be rejected by looking through the front (without consuming state) before building th full DFS state which can be expensive to build only to realize that nothing matches. The pre-check only returns false when every inspected path reaches a first consuming match state that rejects *_M_current, or reaches a dead end. It returns true for unsupported or context-sensitive states such as backrefs and lookahead, so true means "run the normal executor" and false means "this start position cannot match". This mainly helps IPv4-style scans where most positions are non-digits and only a few positions can start a match. Benchmarks improvements compared to GCC previous patch in series: at -O2: email: +2.4% URI: +3.6% IPv4 +43.9% at -O3: email: +0.1%, URI: +1.4% IPv4: +42.7% libstdc++-v3/ChangeLog: PR libstdc++/126274 PR libstdc++/88947 * include/bits/regex_executor.h (_M_search_from_first): Avoid needless recursions. (_M_maybe_start_match): New. * include/bits/regex_executor.tcc (_M_maybe_start_match): New.
