From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2136) id 9766D39578D1; Wed, 17 Jun 2020 19:23:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9766D39578D1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1592421821; bh=kAPmj3RwMzSyRQzQZdCIRH+4rzioVqTsZaM1Q4kVSyc=; h=From:To:Subject:Date:From; b=jwGyWgmTucGc6yZ3NLJRat7EOcuf89XrP2Mm0+WFvh20iA08O4jnnHiYBOwvpBkNU zxJXubePfpCUgaxXM5Yza/5yVJi70ltcQLA8CIguEYEvv389gVxXYft7mE4YgOvcSD fAj2QGp8HMHIcH5MuVphcMZx6J+7bbTN9ds1zPzs= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Aldy Hernandez To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc/devel/ranger] libstdc++: Micro-optimisations for lexicographical_compare_three_way X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/devel/ranger X-Git-Oldrev: b07e4e7c7520ca3e798f514dec0711eea2c027be X-Git-Newrev: 9b4f00dd3f799337d8b8ef5e79f5a682c8059ab9 Message-Id: <20200617192341.9766D39578D1@sourceware.org> Date: Wed, 17 Jun 2020 19:23:41 +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: Wed, 17 Jun 2020 19:23:41 -0000 https://gcc.gnu.org/g:9b4f00dd3f799337d8b8ef5e79f5a682c8059ab9 commit 9b4f00dd3f799337d8b8ef5e79f5a682c8059ab9 Author: Jonathan Wakely Date: Tue Mar 3 11:06:26 2020 +0000 libstdc++: Micro-optimisations for lexicographical_compare_three_way As noted in LWG 3410 the specification in the C++20 draft performs more iterator comparisons than necessary when the end of either range is reached. Our implementation followed that specification. This removes the redundant comparisons so that we do no unnecessary work as soon as we find that we've reached the end of either range. The odd-looking return statement is because it generates better code than the original version that copied the global constants. * include/bits/stl_algobase.h (lexicographical_compare_three_way): Avoid redundant iterator comparisons (LWG 3410). Diff: --- libstdc++-v3/ChangeLog | 5 +++++ libstdc++-v3/include/bits/stl_algobase.h | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 28957dc5c99..b8cf579fdb3 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,8 @@ +2020-03-03 Jonathan Wakely + + * include/bits/stl_algobase.h (lexicographical_compare_three_way): + Avoid redundant iterator comparisons (LWG 3410). + 2020-03-02 Jonathan Wakely PR libstdc++/93972 diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h index 7a9d932b421..4b63086965d 100644 --- a/libstdc++-v3/include/bits/stl_algobase.h +++ b/libstdc++-v3/include/bits/stl_algobase.h @@ -1711,15 +1711,16 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO return __lencmp; } #endif // is_constant_evaluated - while (__first1 != __last1 && __first2 != __last2) + while (__first1 != __last1) { + if (__first2 == __last2) + return strong_ordering::greater; if (auto __cmp = __comp(*__first1, *__first2); __cmp != 0) return __cmp; ++__first1; ++__first2; } - return __first1 != __last1 ? strong_ordering::greater - : __first2 != __last2 ? strong_ordering::less : strong_ordering::equal; + return (__first2 == __last2) <=> true; // See PR 94006 } template