See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98723
From bf651c78c6ad4fedd0fe6cec3d7953cbf0a4f03a Mon Sep 17 00:00:00 2001 From: Luca Bacci <luca.bacci...@gmail.com> Date: Fri, 15 Nov 2024 16:32:14 +0100 Subject: [PATCH] Avoid unneeded calls to regex_traits::transform_primary() To: gcc-patches@gcc.gnu.org
This is both a performance optimization and a partial fix for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98723. This commit fixes the issue for bracket expressions that are not locale-dependant. --- libstdc++-v3/include/bits/regex_compiler.tcc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libstdc++-v3/include/bits/regex_compiler.tcc b/libstdc++-v3/include/bits/regex_compiler.tcc index 3c6cb6649df..2b94ed0aa7a 100644 --- a/libstdc++-v3/include/bits/regex_compiler.tcc +++ b/libstdc++-v3/include/bits/regex_compiler.tcc @@ -608,10 +608,13 @@ namespace __detail return true; if (_M_traits.isctype(__ch, _M_class_set)) return true; - if (std::find(_M_equiv_set.begin(), _M_equiv_set.end(), - _M_traits.transform_primary(&__ch, &__ch+1)) - != _M_equiv_set.end()) - return true; + if (!_M_equiv_set.empty()) + { + if (std::find(_M_equiv_set.begin(), _M_equiv_set.end(), + _M_traits.transform_primary(&__ch, &__ch+1)) + != _M_equiv_set.end()) + return true; + } for (auto& __it : _M_neg_class_set) if (!_M_traits.isctype(__ch, __it)) return true; -- 2.47.0