Commit 113f0a63 by Jonathan Wakely

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.
parent 8017d95c
2020-02-26 Jonathan Wakely <jwakely@redhat.com> 2020-02-26 Jonathan Wakely <jwakely@redhat.com>
* 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 * include/std/ranges (__detail::__maybe_empty_t): Define new helper
alias. alias.
(__detail::__maybe_const_t): Likewise. (__detail::__maybe_const_t): Likewise.
......
...@@ -3464,9 +3464,6 @@ namespace ranges ...@@ -3464,9 +3464,6 @@ namespace ranges
&& sized_sentinel_for<_Sent2, _Iter2>); && sized_sentinel_for<_Sent2, _Iter2>);
if constexpr (__sized_iters) if constexpr (__sized_iters)
{ {
auto __d1 = ranges::distance(__first1, __last1);
auto __d2 = ranges::distance(__first2, __last2);
using _ValueType1 = iter_value_t<_Iter1>; using _ValueType1 = iter_value_t<_Iter1>;
using _ValueType2 = iter_value_t<_Iter2>; using _ValueType2 = iter_value_t<_Iter2>;
constexpr bool __use_memcmp constexpr bool __use_memcmp
...@@ -3480,6 +3477,9 @@ namespace ranges ...@@ -3480,6 +3477,9 @@ namespace ranges
&& is_same_v<_Proj2, identity>); && is_same_v<_Proj2, identity>);
if constexpr (__use_memcmp) if constexpr (__use_memcmp)
{ {
const auto __d1 = __last1 - __first1;
const auto __d2 = __last2 - __first2;
if (const auto __len = std::min(__d1, __d2)) if (const auto __len = std::min(__d1, __d2))
{ {
const auto __c const auto __c
...@@ -3498,10 +3498,8 @@ namespace ranges ...@@ -3498,10 +3498,8 @@ namespace ranges
if (__c < 0) if (__c < 0)
return false; return false;
} }
else
__builtin_unreachable();
} }
return (__last1 - __first1 < __last2 - __first2); return __d1 < __d2;
} }
} }
......
...@@ -1254,21 +1254,16 @@ _GLIBCXX_END_NAMESPACE_CONTAINER ...@@ -1254,21 +1254,16 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
{ {
template<typename _II1, typename _II2> template<typename _II1, typename _II2>
_GLIBCXX20_CONSTEXPR _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<bool _BoolType>
template<typename _II1, typename _II2>
_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<> template<>
struct __lexicographical_compare<true> struct __lexicographical_compare<true>
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment