[libcxx-commits] [libcxx] [libc++] Optimize lexicographical_compare (PR #65279)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Jul 25 09:32:49 PDT 2024
================
@@ -34,23 +36,24 @@ namespace ranges {
namespace __lexicographical_compare {
struct __fn {
template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Proj1, class _Proj2, class _Comp>
- _LIBCPP_HIDE_FROM_ABI constexpr static bool __lexicographical_compare_impl(
+ static _LIBCPP_HIDE_FROM_ABI constexpr bool __lexicographical_compare_unwrap(
_Iter1 __first1,
_Sent1 __last1,
_Iter2 __first2,
_Sent2 __last2,
_Comp& __comp,
_Proj1& __proj1,
_Proj2& __proj2) {
- while (__first2 != __last2) {
- if (__first1 == __last1 || std::invoke(__comp, std::invoke(__proj1, *__first1), std::invoke(__proj2, *__first2)))
- return true;
- if (std::invoke(__comp, std::invoke(__proj2, *__first2), std::invoke(__proj1, *__first1)))
- return false;
- ++__first1;
- ++__first2;
- }
- return false;
+ auto [__first1_un, __last1_un] = std::__unwrap_range(std::move(__first1), std::move(__last1));
+ auto [__first2_un, __last2_un] = std::__unwrap_range(std::move(__first2), std::move(__last2));
+ return std::__lexicographical_compare(
----------------
ldionne wrote:
Don't you need to pass through the `AlgPolicy`? Specifically, you will be calling `std::mismatch` (not `ranges::mismatch`) from here under the hood. Is that fine?
Answer: No, `__mismatch` doesn't accept an algorithm policy.
https://github.com/llvm/llvm-project/pull/65279
More information about the libcxx-commits
mailing list