summaryrefslogtreecommitdiff
path: root/libcxx/src/algorithm.cpp
diff options
context:
space:
mode:
authorNikolas Klauser <nikolasklauser@berlin.de>2023-01-20 09:26:37 +0100
committerNikolas Klauser <nikolasklauser@berlin.de>2023-02-01 20:10:21 +0100
commitdc017e03ca55ed0b2054e4a7d5e5ca049a054fcc (patch)
tree62343f6227361a2713c9830a0151ccd1b9fb5a97 /libcxx/src/algorithm.cpp
parent57690a8ece9e5d3b749c66a226a4c79f3d7588aa (diff)
downloadllvm-dc017e03ca55ed0b2054e4a7d5e5ca049a054fcc.tar.gz
[libc++] Forward ranges::sort to instantiations in the dylib
This patch removes `_WrapAlgPolicy` and related functionality. Instead, we explicitly forward to `__sort` now if we have an instantiation inside the dylib. If we don't we just call `__introsort`. Reviewed By: ldionne, #libc Spies: sstefan1, libcxx-commits Differential Revision: https://reviews.llvm.org/D140824
Diffstat (limited to 'libcxx/src/algorithm.cpp')
-rw-r--r--libcxx/src/algorithm.cpp16
1 files changed, 15 insertions, 1 deletions
diff --git a/libcxx/src/algorithm.cpp b/libcxx/src/algorithm.cpp
index b7535b7513b5..5a47558fdaeb 100644
--- a/libcxx/src/algorithm.cpp
+++ b/libcxx/src/algorithm.cpp
@@ -7,11 +7,24 @@
//===----------------------------------------------------------------------===//
#include <algorithm>
+#include <bit>
_LIBCPP_BEGIN_NAMESPACE_STD
-// TODO(varconst): this currently doesn't benefit `ranges::sort` because it uses `ranges::less` instead of `__less`.
+template <class Comp, class RandomAccessIterator>
+void __sort(RandomAccessIterator first, RandomAccessIterator last, Comp comp) {
+ auto depth_limit = 2 * std::__bit_log2(static_cast<size_t>(last - first));
+ // Only use bitset partitioning for arithmetic types. We should also check
+ // that the default comparator is in use so that we are sure that there are no
+ // branches in the comparator.
+ std::__introsort<_ClassicAlgPolicy,
+ Comp&,
+ RandomAccessIterator,
+ __use_branchless_sort<Comp, RandomAccessIterator>::value>(first, last, comp, depth_limit);
+}
+
+// clang-format off
template void __sort<__less<char>&, char*>(char*, char*, __less<char>&);
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
template void __sort<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&);
@@ -29,5 +42,6 @@ template void __sort<__less<unsigned long long>&, unsigned long long*>(unsigned
template void __sort<__less<float>&, float*>(float*, float*, __less<float>&);
template void __sort<__less<double>&, double*>(double*, double*, __less<double>&);
template void __sort<__less<long double>&, long double*>(long double*, long double*, __less<long double>&);
+// clang-format on
_LIBCPP_END_NAMESPACE_STD