From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id DF960384F010 for ; Thu, 16 Jun 2022 19:21:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DF960384F010 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-443-DPWr9KBRPSSbjTE5HYOexA-1; Thu, 16 Jun 2022 15:21:07 -0400 X-MC-Unique: DPWr9KBRPSSbjTE5HYOexA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B5B4C811E7A; Thu, 16 Jun 2022 19:21:06 +0000 (UTC) Received: from localhost (unknown [10.33.36.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id 75A3340885A1; Thu, 16 Jun 2022 19:21:06 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Apply r13-1096-g6abe341558abec change to vstring too [PR101482] Date: Thu, 16 Jun 2022 20:21:05 +0100 Message-Id: <20220616192105.1199634-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Jun 2022 19:21:12 -0000 Tested x86_64-linux, pushed to trunk. -- >8 -- 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. --- libstdc++-v3/include/ext/vstring.h | 49 ++++++++++++++---------------- 1 file changed, 22 insertions(+), 27 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,31 +2338,10 @@ _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; } - - 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())); } - - /** - * @brief Test equivalence of C string and string. - * @param __lhs C string. - * @param __rhs String. - * @return True if @a __rhs.compare(@a __lhs) == 0. False otherwise. - */ - template class _Base> - inline bool - operator==(const _CharT* __lhs, - const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) - { return __rhs.compare(__lhs) == 0; } + { + return __lhs.size() == __rhs.size() + && !_Traits::compare(__lhs.data(), __rhs.data(), __lhs.size()); + } /** * @brief Test equivalence of string and C string. @@ -2375,7 +2354,23 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION inline bool operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, const _CharT* __rhs) - { return __lhs.compare(__rhs) == 0; } + { + return __lhs.size() == _Traits::length(__rhs) + && !_Traits::compare(__lhs.data(), __rhs, __lhs.size()); + } + + /** + * @brief Test equivalence of C string and string. + * @param __lhs C string. + * @param __rhs String. + * @return True if @a __rhs.compare(@a __lhs) == 0. False otherwise. + */ + template class _Base> + inline bool + operator==(const _CharT* __lhs, + const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) + { 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. -- 2.34.3