From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 043A13857B80; Thu, 16 Jun 2022 19:20:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 043A13857B80 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r13-1138] libstdc++: Apply r13-1096-g6abe341558abec change to vstring too [PR101482] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: 9ca05d5d9b9b2bcbdc00add8a3b86d3c3361f1a1 X-Git-Newrev: 51309d1158b85560a975819260776c0ca68fd142 Message-Id: <20220616192047.043A13857B80@sourceware.org> Date: Thu, 16 Jun 2022 19:20:47 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Jun 2022 19:20:47 -0000 https://gcc.gnu.org/g:51309d1158b85560a975819260776c0ca68fd142 commit r13-1138-g51309d1158b85560a975819260776c0ca68fd142 Author: Jonathan Wakely Date: Thu Jun 16 11:02:11 2022 +0100 libstdc++: Apply r13-1096-g6abe341558abec change to vstring too [PR101482] As recently done for std::basic_string, __gnu_cxx::__versa_string equality comparisons can check lengths first for any character type and traits type, not only for std::char_traits. libstdc++-v3/ChangeLog: PR libstdc++/101482 * include/ext/vstring.h (operator==): Always check lengths before comparing. Diff: --- libstdc++-v3/include/ext/vstring.h | 45 +++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/libstdc++-v3/include/ext/vstring.h b/libstdc++-v3/include/ext/vstring.h index 4406695919d..47cbabf24f1 100644 --- a/libstdc++-v3/include/ext/vstring.h +++ b/libstdc++-v3/include/ext/vstring.h @@ -2338,18 +2338,26 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION inline bool operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) - { return __lhs.compare(__rhs) == 0; } + { + return __lhs.size() == __rhs.size() + && !_Traits::compare(__lhs.data(), __rhs.data(), __lhs.size()); + } - template class _Base> - inline typename __enable_if::__value, bool>::__type - operator==(const __versa_string<_CharT, std::char_traits<_CharT>, - std::allocator<_CharT>, _Base>& __lhs, - const __versa_string<_CharT, std::char_traits<_CharT>, - std::allocator<_CharT>, _Base>& __rhs) - { return (__lhs.size() == __rhs.size() - && !std::char_traits<_CharT>::compare(__lhs.data(), __rhs.data(), - __lhs.size())); } + inline bool + operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, + const _CharT* __rhs) + { + return __lhs.size() == _Traits::length(__rhs) + && !_Traits::compare(__lhs.data(), __rhs, __lhs.size()); + } /** * @brief Test equivalence of C string and string. @@ -2362,20 +2370,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION inline bool operator==(const _CharT* __lhs, const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) - { return __rhs.compare(__lhs) == 0; } - - /** - * @brief Test equivalence of string and C string. - * @param __lhs String. - * @param __rhs C string. - * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise. - */ - template class _Base> - inline bool - operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, - const _CharT* __rhs) - { return __lhs.compare(__rhs) == 0; } + { return __rhs == __lhs; } // operator != /** @@ -2402,7 +2397,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION inline bool operator!=(const _CharT* __lhs, const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) - { return !(__lhs == __rhs); } + { return !(__rhs == __lhs); } /** * @brief Test difference of string and C string.