[libcxx-commits] [PATCH] D150831: [libc++] Implement ranges::ends_with

Nikolas Klauser via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Aug 18 18:08:28 PDT 2023


philnik requested changes to this revision.
philnik added a comment.
This revision now requires changes to proceed.

Looks pretty good, but I'd like to get the `ranges::equal` optimization in again, since it's probably quite significant.



================
Comment at: libcxx/include/__algorithm/ranges_ends_with.h:36
+namespace ranges {
+namespace __ends_with {
+struct __fn {
----------------
It looks like we've dropped the `ranges::equal` optimization again?


================
Comment at: libcxx/include/__algorithm/ranges_ends_with.h:64-82
+    if constexpr (std::bidirectional_iterator<_Sent1> && std::bidirectional_iterator<_Sent2>) {
+      return __bidirectional_impl(__first1, __last1, __first2, __last2, __pred, __proj1, __proj2);
+    }
+    auto __n1 = ranges::distance(__first1, __last1);
+    auto __n2 = ranges::distance(__first2, __last2);
+    if (__n2 == 0)
+      return true;
----------------
Just to make it a bit leaner to compile.


================
Comment at: libcxx/include/__algorithm/ranges_ends_with.h:147-148
+    if constexpr (sized_range<_Range1> && sized_range<_Range2>) {
+      auto __n1 = ranges::distance(__range1);
+      auto __n2 = ranges::distance(__range2);
+      if (__n2 == 0)
----------------
To make it obvious that it's constant time and avoid a few instantiations.


================
Comment at: libcxx/include/__algorithm/ranges_ends_with.h:164-172
+    }
+    return __ends_with_fn_impl(
+        std::move(ranges::begin(__range1)),
+        std::move(ranges::end(__range1)),
+        std::move(ranges::begin(__range2)),
+        std::move(ranges::end(__range2)),
+        __pred,
----------------



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150831/new/

https://reviews.llvm.org/D150831



More information about the libcxx-commits mailing list