https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126274
--- 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:a0b77a14fed845f742ef378d6cb911c8d78ed625 commit r17-4555-ga0b77a14fed845f742ef378d6cb911c8d78ed625 Author: Tamar Christina <[email protected]> Date: Tue Sep 22 07:23:41 2026 +0100 libstdc++: Inline simple regex repeating matches in DFS [PR126274] Optimize the common DFS NFA shape repeat -> match -> repeat, which is produced by repeated character classes such as [\w]+, [^\s?#]+, and #+. Since the second patch the DFS continuation already avoids pushing a separate _S_fopcode_next frame for many states. This patch adds a small improvement for greedy repeats. After creating the same fallback and repeat bookkeeping frames as before, if the repeated body is a single match state that returns to the repeat state, consume that match state immediately and continue at the repeat. Backtracking behavior is unchanged. _M_rep_once_more still creates the restore/decrement frames, and the repeat exit fallback is still saved before trying the body. If the body match fails, the helper returns _S_invalid_state_id so the normal frame loop restores repeat state and tries pending fallbacks. Benchmarks improvements compared to GCC previous patch in series: at -O2: email: +4.7% URI: +5.1% IPv4 -1.1% at -O3: email: +4.5%, URI: +4.1% IPv4: -0.2% And finally gets us better than GCC 15. I outlined the helper into _M_match_simple_repeat_body since that looks more readable. libstdc++-v3/ChangeLog: PR libstdc++/126274 * include/bits/regex_executor.h (_M_match_simple_repeat_body): New. * include/bits/regex_executor.tcc (_M_dfs_next): Inline consume matches on _S_opcode_repeat. (_M_match_simple_repeat_body): New.
