Skip to content

Commit d4ffccf

Browse files
authored
[libc++] Simplify the implementation of std::sort a bit (#104902)
This does a few things to canonicalize the library a bit. Specifically - use `__desugars_to_v` instead of the custom `__is_simple_comparator` - make `__use_branchless_sort` an inline variable - remove the `_maybe_branchless` versions of the `__sortN` functions and overload based on whether we can do branchless sorting instead.
1 parent e886374 commit d4ffccf

File tree

8 files changed

+150
-171
lines changed

8 files changed

+150
-171
lines changed

libcxx/include/__algorithm/comp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ struct __less<void, void> {
4242
}
4343
};
4444

45+
template <class _Tp>
46+
inline const bool __desugars_to_v<__less_tag, __less<>, _Tp, _Tp> = true;
47+
4548
template <class _Tp>
4649
inline const bool __desugars_to_v<__totally_ordered_less_tag, __less<>, _Tp, _Tp> = is_integral<_Tp>::value;
4750

libcxx/include/__algorithm/ranges_minmax.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ struct __minmax {
8888
// vectorize the code.
8989
if constexpr (contiguous_range<_Range> && is_integral_v<_ValueT> &&
9090
__is_cheap_to_copy<_ValueT> & __is_identity<_Proj>::value &&
91-
__desugars_to_v<__totally_ordered_less_tag, _Comp, _ValueT, _ValueT>) {
91+
__desugars_to_v<__less_tag, _Comp, _ValueT, _ValueT>) {
9292
minmax_result<_ValueT> __result = {__r[0], __r[0]};
9393
for (auto __e : __r) {
9494
if (__e < __result.min)

0 commit comments

Comments
 (0)