[libcxx-commits] [libcxx] [libc++] Tiny optimizations for is_permutation (PR #129565)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Mar 19 14:06:36 PDT 2025


================
@@ -117,10 +121,9 @@ template <class _AlgPolicy, class _ForwardIterator1, class _Sentinel1, class _Fo
 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __is_permutation(
     _ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterator2 __first2, _BinaryPredicate&& __pred) {
   // Shorten sequences as much as possible by lopping of any equal prefix.
-  for (; __first1 != __last1; ++__first1, (void)++__first2) {
-    if (!__pred(*__first1, *__first2))
-      break;
-  }
+  auto __result = std::mismatch(__first1, __last1, __first2, std::ref(__pred));
----------------
ldionne wrote:

There's another potential `mismatch` call below on line 163, I think.

https://github.com/llvm/llvm-project/pull/129565


More information about the libcxx-commits mailing list