public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r10-9982] libstdc++: Simplify basic_string_view::ends_with [PR 101361]
@ 2021-07-14 16:04 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2021-07-14 16:04 UTC (permalink / raw)
  To: gcc-cvs, libstdc++-cvs

https://gcc.gnu.org/g:a8ae5dbc60eedade3514e51e3cb35fd28ec1d4c8

commit r10-9982-ga8ae5dbc60eedade3514e51e3cb35fd28ec1d4c8
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Jul 13 12:21:27 2021 +0100

    libstdc++: Simplify basic_string_view::ends_with [PR 101361]
    
    The use of npos triggers a diagnostic as described in PR c++/101361.
    This change replaces the use of npos with the exact length, which is
    already known. We can further simplify it by inlining the effects of
    compare and substr, avoiding the redundant range checks in the latter.
    
    Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
    
    libstdc++-v3/ChangeLog:
    
            PR c++/101361
            * include/std/string_view (ends_with): Use traits_type::compare
            directly.
    
    (cherry picked from commit 4d3eaeb4f505b0838c673ee28e7dba8687fc8272)

Diff:
---
 libstdc++-v3/include/std/string_view | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/std/string_view b/libstdc++-v3/include/std/string_view
index da23f9bc855..7e8ccbdd9e4 100644
--- a/libstdc++-v3/include/std/string_view
+++ b/libstdc++-v3/include/std/string_view
@@ -338,8 +338,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       constexpr bool
       ends_with(basic_string_view __x) const noexcept
       {
-	return this->size() >= __x.size()
-	    && this->compare(this->size() - __x.size(), npos, __x) == 0;
+	const auto __len = this->size();
+	const auto __xlen = __x.size();
+	return __len >= __xlen
+	  && traits_type::compare(end() - __xlen, __x.data(), __xlen) == 0;
       }
 
       constexpr bool


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-07-14 16:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-14 16:04 [gcc r10-9982] libstdc++: Simplify basic_string_view::ends_with [PR 101361] Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).