From: Luca Bacci Date: Tue, 17 Dec 2024 18:57:30 +0000 (+0000) Subject: libstdc++: Call regex_traits::transform_primary() only when necessary [PR98723] X-Git-Tag: basepoints/gcc-16~3236 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eb339c29ee42aa59591fc50d6d8a1ab903d2a3fe;p=thirdparty%2Fgcc.git libstdc++: Call regex_traits::transform_primary() only when necessary [PR98723] This is both a performance optimization and a partial fix for PR 98723. This commit fixes the issue for bracket expressions that do not depend on the locale's collation facet. Examples: * Character ranges ([a-z]) when std::regex::collate is not set * Character classes ([:alnum:]) * Individual characters ([abc]) Signed-off-by: Luca Bacci libstdc++-v3/ChangeLog: PR libstdc++/98723 * include/bits/regex_compiler.tcc (_BracketMatcher::_M_apply): Only use transform_primary when an equivalence set is used. --- diff --git a/libstdc++-v3/include/bits/regex_compiler.tcc b/libstdc++-v3/include/bits/regex_compiler.tcc index 9c5a46a47cd0..5037195ca17a 100644 --- a/libstdc++-v3/include/bits/regex_compiler.tcc +++ b/libstdc++-v3/include/bits/regex_compiler.tcc @@ -611,10 +611,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()) + { + auto __x = _M_traits.transform_primary(&__ch, &__ch+1); + auto __p = std::find(_M_equiv_set.begin(), _M_equiv_set.end(), __x); + if (__p != _M_equiv_set.end()) + return true; + } for (auto& __it : _M_neg_class_set) if (!_M_traits.isctype(__ch, __it)) return true;