aboutsummaryrefslogtreecommitdiff
path: root/libjava/classpath/missing
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2026-02-09 20:04:00 -0500
committerPatrick Palka <ppalka@redhat.com>2026-02-09 20:04:00 -0500
commitc49ce07bf09504d1eca66ac7359ca92eab63f106 (patch)
tree1efc432d1fb6d713f1e992fca256bbb70434f67d /libjava/classpath/missing
parent0c763ab721b3bc882b6ed7a25ceccfb0639aa13f (diff)
downloadgcc-c49ce07bf09504d1eca66ac7359ca92eab63f106.zip
gcc-c49ce07bf09504d1eca66ac7359ca92eab63f106.tar.gz
gcc-c49ce07bf09504d1eca66ac7359ca92eab63f106.tar.bz2
libstdc++/regex: Replace __dfs_mode template parameter with run-time flag
That _Executor's __dfs_mode flag is a template parameter means __regex_algo_impl has to instantiate two different (but largely the same) versions of _Executor even though the BFS version is rarely used. And it seems the compiler has trouble DCEing the unused version of _Executor, which needlessly increases code size and burdens the optimizer. This patch replaces the template parameter with a run-time data member _M_search_mode. We in turn need to inline the _Executor::_State_info member functions and data members into _Executor so that they depend on the run-time instead of compile-time flag. This means _Executor is three pointers bigger in DFS mode (due to the unused _M_match_queue and _M_visited_states members), which we can reduce to one pointer if we really want to, but that doesn't seem ver worthwhile. The __dfs_mode template parameter is now unused but not yet removed, that'll be done in the next patch. After this patch, both code size and run time for the microbenchmark for (int i = 0; i < 10000; i++) regex_match(string(200, 'a'), regex("(a|b|c)*")); decreases by about 15% each (with -O2). Compile time/memory use decreases by 5-10%. libstdc++-v3/ChangeLog: * include/bits/regex.tcc (__regex_algo_impl): Pass __use_dfs parameter to _Executor's constructor. * include/bits/regex_executor.h (_Executor::_Search_mode): New. (_Executor::_Executor): Add __use_dfs parameter and initialize _M_search_mode. Adjust after inlining _State_info members into _Executor. (_Executor::~_Executor): Free _M_visted_states. (_Executor::_M_main): Adjust after renaming _M_main_dispatch overloads to _M_main_dfs and _M_main_bfs. (_Executor::_State_info): Remove. (_Executor::_M_visited): Inlined from _State_info. (_Executor::_M_get_sol_pos): Likewise. (_Executor::_M_states): Remove. (_Executor::_M_start): Inlined from _State_info. (_Executor::_M_sol_pos): Likewise. (_Executor::_M_match_queue): Likewise. (_Executor::_M_search_mode): New. * include/bits/regex_executor.tcc (_Executor::_M_main_dispatch): Renamed to... (_Executor::_M_main_dfs, _Executor::_M_main_bfs): ... these. (_Executor::_M_*): Adjust after _M_states removal. (_Executor::_M_lookhead): Also adjust _Executor constructor call. Reviewed-by: Tomasz KamiƄski <tkaminsk@redhat.com> Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Diffstat (limited to 'libjava/classpath/missing')
0 files changed, 0 insertions, 0 deletions