[libcxx-commits] [libcxx] [libc++] Optimize std::find for segmented iterators (PR #67224)

via libcxx-commits libcxx-commits at lists.llvm.org
Fri Oct 20 15:47:16 PDT 2023


================
@@ -118,8 +119,35 @@ __find_impl(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst>
   return std::__find_bool<false>(__first, static_cast<typename _Cp::size_type>(__last - __first));
 }
 
+// segmented iterator implementation
+
+template <class>
+struct __find_segment;
+
+template <class _SegmentedIterator,
+          class _Tp,
+          class _Proj,
+          __enable_if_t<__is_segmented_iterator<_SegmentedIterator>::value, int> = 0>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _SegmentedIterator
+__find_impl(_SegmentedIterator __first, _SegmentedIterator __last, const _Tp& __value, _Proj& __proj) {
+  return std::__find_segment_if(std::move(__first), std::move(__last), __find_segment<_Tp>(__value), __proj);
+}
+
+template <class _Tp>
+struct __find_segment {
+  const _Tp& __value_;
+
+  __find_segment(const _Tp& __value) : __value_(__value) {}
----------------
EricWF wrote:

constexpr?

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


More information about the libcxx-commits mailing list