mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
libcxx: backport llvm/llvm-project#155476
https://github.com/llvm/llvm-project/pull/155476
This commit is contained in:
parent
958faa7031
commit
820dc9d767
3 changed files with 8 additions and 0 deletions
3
lib/libcxx/include/__algorithm/sort.h
vendored
3
lib/libcxx/include/__algorithm/sort.h
vendored
|
|
@ -860,6 +860,9 @@ __sort<__less<long double>&, long double*>(long double*, long double*, __less<lo
|
|||
template <class _AlgPolicy, class _RandomAccessIterator, class _Comp>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
|
||||
__sort_dispatch(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp& __comp) {
|
||||
if (__first == __last) // log(0) is undefined, so don't try computing the depth
|
||||
return;
|
||||
|
||||
typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
|
||||
difference_type __depth_limit = 2 * std::__bit_log2(std::__to_unsigned_like(__last - __first));
|
||||
|
||||
|
|
|
|||
2
lib/libcxx/include/__bit/bit_log2.h
vendored
2
lib/libcxx/include/__bit/bit_log2.h
vendored
|
|
@ -9,6 +9,7 @@
|
|||
#ifndef _LIBCPP___BIT_BIT_LOG2_H
|
||||
#define _LIBCPP___BIT_BIT_LOG2_H
|
||||
|
||||
#include <__assert>
|
||||
#include <__bit/countl.h>
|
||||
#include <__config>
|
||||
#include <__type_traits/integer_traits.h>
|
||||
|
|
@ -23,6 +24,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
|
|||
template <class _Tp>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp __bit_log2(_Tp __t) _NOEXCEPT {
|
||||
static_assert(__is_unsigned_integer_v<_Tp>, "__bit_log2 requires an unsigned integer type");
|
||||
_LIBCPP_ASSERT_INTERNAL(__t != 0, "logarithm of 0 is undefined");
|
||||
return numeric_limits<_Tp>::digits - 1 - std::__countl_zero(__t);
|
||||
}
|
||||
|
||||
|
|
|
|||
3
lib/libcxx/src/algorithm.cpp
vendored
3
lib/libcxx/src/algorithm.cpp
vendored
|
|
@ -13,6 +13,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD
|
|||
|
||||
template <class Comp, class RandomAccessIterator>
|
||||
void __sort(RandomAccessIterator first, RandomAccessIterator last, Comp comp) {
|
||||
if (first == last) // log(0) is undefined, so don't try computing the depth
|
||||
return;
|
||||
|
||||
auto depth_limit = 2 * std::__bit_log2(static_cast<size_t>(last - first));
|
||||
|
||||
// Only use bitset partitioning for arithmetic types. We should also check
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue