https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86164

--- Comment #18 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <[email protected]>:

https://gcc.gnu.org/g:ead66d5f229edda244d1a91125524eca9abdb9b9

commit r16-7194-gead66d5f229edda244d1a91125524eca9abdb9b9
Author: Patrick Palka <[email protected]>
Date:   Fri Jan 30 12:29:17 2026 -0500

    libstdc++/regex: Defer _M_current restoration to backtracking nodes
[PR86164]

    The incrementing of the current input string position (_M_current) is
    done by _M_handle_match, which also makes sure to restore it afterwards,
    via a restore_current frame.  But restoring _M_current is naturally only
    necessary when backtracking is involved, not after every single match.

    So this patch moves the responsibility of saving/restoring _M_current
    from _M_handle_match to the branching nodes _M_handle_alternative and
    _M_handle_repeat.  This is done by storing _M_current within the
    fallback_next, fallback_rep_once_more and posix_alternative frames.
    In turn we can get rid of the now unused restore_current frame kind.

    This reduces the maximum size of the _M_frames stack by 15% for

      regex_match(string(200000, 'a'), "(a|b|c)*")

            PR libstdc++/86164

    libstdc++-v3/ChangeLog:

            * include/bits/regex_executor.tcc (__detail::_ExecutorFrameOpcode):
            Remove _S_fopcode_restore_current.
            (__detail::_Executor::_M_handle_repeat): Pass _M_current when
            pushing a fallback_next or fallback_rep_once_more frame.
            (__detail::_Executor::_M_handle_match): Don't push a
            restore_current frame.
            (__detail::_Executor::_M_handle_backref): Likewise and simplify
            accordingly.
            (__detail::_Executor::_M_handle_alternative): Pass _M_current when
            pushing a fallback_next or posix_alternative frame.
            (__detail::_Executor::_M_dfs) <case _S_fopcode_fallback_next>:
            Restore _M_current.
            <case _S_fopcode_fallback_rep_once_more>: Likewise.
            <case _S_fopcode_posix_alternative>: Likewise.
            <case _S_fopcode_restore_current>: Remove.

    Reviewed-by: Tomasz KamiÅski <[email protected]>
    Reviewed-by: Jonathan Wakely <[email protected]>

Reply via email to