]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++/regex: add [[gnu::always_inline]] to _Executor::_M_node
authorPatrick Palka <ppalka@redhat.com>
Fri, 30 Jan 2026 18:16:20 +0000 (13:16 -0500)
committerPatrick Palka <ppalka@redhat.com>
Fri, 30 Jan 2026 18:16:20 +0000 (13:16 -0500)
The compiler understandably doesn't know that _M_node only ever has a
single call site, _M_dfs, (and is not directly called from other library
headers or user code) and so decides not to inline it.  So use the
always_inline attribute to force the inlining.  This seems sufficient to
make all _M_dfs subroutines get inlined away, and speeds up the executor
by 30% on some microbenchmarks.

libstdc++-v3/ChangeLog:

* include/bits/regex_executor.tcc (__detail::_Executor::_M_node)
[__OPTIMIZE__]: Add [[gnu::always_inline]] attribute.  Declare
inline.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/include/bits/regex_executor.tcc

index ccdec934b49cbb3ff961569a213d738e13808a38..3412ad683e4688da5c1316514eafec71a9645ae4 100644 (file)
@@ -578,7 +578,10 @@ _GLIBCXX_BEGIN_INLINE_ABI_NAMESPACE(_V2)
 
   template<typename _BiIter, typename _Alloc, typename _TraitsT,
           bool __dfs_mode>
-    void _Executor<_BiIter, _Alloc, _TraitsT, __dfs_mode>::
+#ifdef __OPTIMIZE__
+    [[__gnu__::__always_inline__]]
+#endif
+    inline void _Executor<_BiIter, _Alloc, _TraitsT, __dfs_mode>::
     _M_node(_Match_mode __match_mode, _StateIdT __i)
     {
       if (_M_states._M_visited(__i))