mirror of
https://github.com/gcc-mirror/gcc.git
synced 2026-05-06 14:59:39 +02:00
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 <tkaminsk@redhat.com> Reviewed-by: Jonathan Wakely <jwakely@redhat.com>