[libcxx-commits] [PATCH] D155136: [libc++][PSTL] Add a __parallel_sort implementation to libdispatch
Louis Dionne via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Jul 17 14:36:03 PDT 2023
ldionne added inline comments.
================
Comment at: libcxx/include/__algorithm/pstl_backends/cpu_backends/libdispatch.h:237-243
+ // Initialize all elements to a moved-from state
+ // TODO: Don't do this - this can be done in the first merge
+ std::__construct_at(__values.get(), std::move(*__first));
+ for (__iter_diff_t<_RandomAccessIterator> __i = 1; __i != __size; ++__i) {
+ std::__construct_at(__values.get() + __i, std::move(__values.get()[__i - 1]));
+ }
+ *__first = std::move(__values.get()[__size - 1]);
----------------
ldionne wrote:
> We could remove this and instead use something like:
>
> ```
> template <class _Tp>
> _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI _Tp* __relocate_at(_Tp* __location, type_identity_t<_Tp>&& __object) {
> _Tp* __result = std::construct_at(__location, std::move(__object));
> std::destroy_at(std::addressof(__object));
> return __result;
> }
> ```
>
> And then:
>
> ```
> template <class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator, class _CopyOrRelocate, class _CopyOrRelocateN>
> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
> _OutputIterator
> __merge(_InputIterator1 __first1, _InputIterator1 __last1,
> _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp,
> _CopyOrRelocate __copy, _CopyOrRelocateN __copy_n)
> {
> for (; __first1 != __last1; ++__result)
> {
> if (__first2 == __last2)
> return __copy(__first1, __last1, __result);
> if (__comp(*__first2, *__first1))
> {
> __copy_n(__first2, 1, __result);
> ++__first2;
> }
> else
> {
> __copy_n(__first1, 1, __result);
> ++__first1;
> }
> }
> return __copy(__first2, __last2, __result);
> }
> ```
>
> And we can pass it `__relocate` and `__relocate_n` in our case, and `__copy` and `__copy_n` in the normal case.
>
Tracked as https://github.com/llvm/llvm-project/issues/63928 to avoid blocking this patch. Please leave a ref to that bug report in a comment.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D155136/new/
https://reviews.llvm.org/D155136
More information about the libcxx-commits
mailing list