diff --git a/include/oneapi/dpl/pstl/algorithm_impl.h b/include/oneapi/dpl/pstl/algorithm_impl.h index 5c33a2ea8c0..1bd1c16083f 100644 --- a/include/oneapi/dpl/pstl/algorithm_impl.h +++ b/include/oneapi/dpl/pstl/algorithm_impl.h @@ -2949,38 +2949,37 @@ __pattern_remove_if(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, // merge //------------------------------------------------------------------------ -template -std::pair -__brick_merge_out_lim(It1 __it_1, It1 __it_1_e, It2 __it_2, It2 __it_2_e, ItOut __it_out, ItOut __it_out_e, +template +std::pair<_Iterator1, _Iterator2> +__brick_merge_out_lim(_Iterator1 __x, _Iterator1 __x_e, _Iterator2 __y, _Iterator2 __y_e, _Iterator3 __i, _Iterator3 __j, _Comp __comp, /* __is_vector = */ std::false_type) { - while (__it_1 != __it_1_e && __it_2 != __it_2_e) + for (_Iterator3 __k = __i; __k < __j; ++__k) { - if (std::invoke(__comp, *__it_1, *__it_2)) + if (__x == __x_e) + { + assert(__y != __y_e); + *__k = *__y; + ++__y; + } + else if (__y == __y_e) + { + assert(__x != __x_e); + *__k = *__x; + ++__x; + } + else if (std::invoke(__comp, *__x, *__y)) { - *__it_out = *__it_1; - ++__it_out, ++__it_1; + *__k = *__x; + ++__x; } else { - *__it_out = *__it_2; - ++__it_out, ++__it_2; + *__k = *__y; + ++__y; } - if (__it_out == __it_out_e) - return {__it_1, __it_2}; - } - - if (__it_1 == __it_1_e) - { - for (; __it_2 != __it_2_e && __it_out != __it_out_e; ++__it_2, ++__it_out) - *__it_out = *__it_2; - } - else - { - for (; __it_1 != __it_1_e && __it_out != __it_out_e; ++__it_1, ++__it_out) - *__it_out = *__it_1; } - return {__it_1, __it_2}; + return {__x, __y}; } template diff --git a/include/oneapi/dpl/pstl/parallel_backend_tbb.h b/include/oneapi/dpl/pstl/parallel_backend_tbb.h index 36be7509994..ef07e457caf 100644 --- a/include/oneapi/dpl/pstl/parallel_backend_tbb.h +++ b/include/oneapi/dpl/pstl/parallel_backend_tbb.h @@ -713,6 +713,8 @@ class __root_task : public __task }; #endif // TBB_INTERFACE_VERSION <= 12000 +inline constexpr _SizeType __merge_cut_off = 2000; + template class __merge_func @@ -732,8 +734,6 @@ class __merge_func _LeafMerge _M_leaf_merge; _SizeType _M_nsort; //number of elements to be sorted for partial_sort algorithm - static const _SizeType __merge_cut_off = 2000; - bool _root; //means a task is merging root task bool _x_orig; //"true" means X(or left ) subrange is in the original container; false - in the buffer bool _y_orig; //"true" means Y(or right) subrange is in the original container; false - in the buffer