From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2136) id 144D03954C68; Wed, 17 Jun 2020 19:12:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 144D03954C68 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1592421179; bh=LaRFYrqQA0DMHHkmD7FV5FLRamX1ilBf7bHFvbf6Hew=; h=From:To:Subject:Date:From; b=j2spy/ekH0nhf4ccDK9meOffs7boViIL413RKgvTC6YZxkqcZe7y/cbJExmEd+XaF kuGN5qGtuZXzXrBgN75gIGGAVjQYsxWVTxFnG/9ZRTWafTQrvLEQV7A7tsqlpo/wk/ 14c2I78CBLsPoO124UV/SFSgbiv+Q2R0cj7WUf0w= 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++ Two simplifications for lexicographical_compare X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/devel/ranger X-Git-Oldrev: 8017d95c7f55b98bcee1caf0216fdfd7fd613849 X-Git-Newrev: 113f0a639dbdd78048373a253ec64145ead7d29d Message-Id: <20200617191259.144D03954C68@sourceware.org> Date: Wed, 17 Jun 2020 19:12:59 +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:12:59 -0000 https://gcc.gnu.org/g:113f0a639dbdd78048373a253ec64145ead7d29d commit 113f0a639dbdd78048373a253ec64145ead7d29d Author: Jonathan Wakely Date: Wed Feb 26 15:19:44 2020 +0000 libstdc++ Two simplifications for lexicographical_compare * include/bits/ranges_algo.h (__lexicographical_compare_fn): Declare variables in smaller scope and avoid calling ranges::distance when we know they are pointers. Remove statically-unreachable use of __builtin_unreachable(). * include/bits/stl_algobase.h (__lexicographical_compare::__lc): Define inline. Diff: --- libstdc++-v3/ChangeLog | 7 +++++++ libstdc++-v3/include/bits/ranges_algo.h | 10 ++++------ libstdc++-v3/include/bits/stl_algobase.h | 21 ++++++++------------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index c13d6fc48f4..d545526d93a 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,12 @@ 2020-02-26 Jonathan Wakely + * include/bits/ranges_algo.h (__lexicographical_compare_fn): Declare + variables in smaller scope and avoid calling ranges::distance when we + know they are pointers. Remove statically-unreachable use of + __builtin_unreachable(). + * include/bits/stl_algobase.h (__lexicographical_compare::__lc): + Define inline. + * include/std/ranges (__detail::__maybe_empty_t): Define new helper alias. (__detail::__maybe_const_t): Likewise. diff --git a/libstdc++-v3/include/bits/ranges_algo.h b/libstdc++-v3/include/bits/ranges_algo.h index 7d7dbf04103..05c0851d411 100644 --- a/libstdc++-v3/include/bits/ranges_algo.h +++ b/libstdc++-v3/include/bits/ranges_algo.h @@ -3464,9 +3464,6 @@ namespace ranges && sized_sentinel_for<_Sent2, _Iter2>); if constexpr (__sized_iters) { - auto __d1 = ranges::distance(__first1, __last1); - auto __d2 = ranges::distance(__first2, __last2); - using _ValueType1 = iter_value_t<_Iter1>; using _ValueType2 = iter_value_t<_Iter2>; constexpr bool __use_memcmp @@ -3480,6 +3477,9 @@ namespace ranges && is_same_v<_Proj2, identity>); if constexpr (__use_memcmp) { + const auto __d1 = __last1 - __first1; + const auto __d2 = __last2 - __first2; + if (const auto __len = std::min(__d1, __d2)) { const auto __c @@ -3498,10 +3498,8 @@ namespace ranges if (__c < 0) return false; } - else - __builtin_unreachable(); } - return (__last1 - __first1 < __last2 - __first2); + return __d1 < __d2; } } diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h index 268569336b0..e4f7fa417ed 100644 --- a/libstdc++-v3/include/bits/stl_algobase.h +++ b/libstdc++-v3/include/bits/stl_algobase.h @@ -1254,21 +1254,16 @@ _GLIBCXX_END_NAMESPACE_CONTAINER { template _GLIBCXX20_CONSTEXPR - static bool __lc(_II1, _II1, _II2, _II2); + static bool + __lc(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2) + { + using __gnu_cxx::__ops::__iter_less_iter; + return std::__lexicographical_compare_impl(__first1, __last1, + __first2, __last2, + __iter_less_iter()); + } }; - template - template - _GLIBCXX20_CONSTEXPR - bool - __lexicographical_compare<_BoolType>:: - __lc(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2) - { - return std::__lexicographical_compare_impl(__first1, __last1, - __first2, __last2, - __gnu_cxx::__ops::__iter_less_iter()); - } - template<> struct __lexicographical_compare {