|
17 | 17 | #include <__algorithm/partial_sort.h>
|
18 | 18 | #include <__algorithm/unwrap_iter.h>
|
19 | 19 | #include <__assert>
|
| 20 | +#include <__bit/bit_log2.h> |
20 | 21 | #include <__bit/blsr.h>
|
21 | 22 | #include <__bit/countl.h>
|
22 | 23 | #include <__bit/countr.h>
|
|
34 | 35 | #include <__type_traits/is_constant_evaluated.h>
|
35 | 36 | #include <__type_traits/is_same.h>
|
36 | 37 | #include <__type_traits/is_trivially_copyable.h>
|
| 38 | +#include <__type_traits/make_unsigned.h> |
37 | 39 | #include <__utility/move.h>
|
38 | 40 | #include <__utility/pair.h>
|
39 | 41 | #include <climits>
|
@@ -826,25 +828,6 @@ void __introsort(_RandomAccessIterator __first,
|
826 | 828 | }
|
827 | 829 | }
|
828 | 830 |
|
829 |
| -template <typename _Number> |
830 |
| -inline _LIBCPP_HIDE_FROM_ABI _Number __log2i(_Number __n) { |
831 |
| - if (__n == 0) |
832 |
| - return 0; |
833 |
| - if (sizeof(__n) <= sizeof(unsigned)) |
834 |
| - return sizeof(unsigned) * CHAR_BIT - 1 - __libcpp_clz(static_cast<unsigned>(__n)); |
835 |
| - if (sizeof(__n) <= sizeof(unsigned long)) |
836 |
| - return sizeof(unsigned long) * CHAR_BIT - 1 - __libcpp_clz(static_cast<unsigned long>(__n)); |
837 |
| - if (sizeof(__n) <= sizeof(unsigned long long)) |
838 |
| - return sizeof(unsigned long long) * CHAR_BIT - 1 - __libcpp_clz(static_cast<unsigned long long>(__n)); |
839 |
| - |
840 |
| - _Number __log2 = 0; |
841 |
| - while (__n > 1) { |
842 |
| - __log2++; |
843 |
| - __n >>= 1; |
844 |
| - } |
845 |
| - return __log2; |
846 |
| -} |
847 |
| - |
848 | 831 | template <class _Comp, class _RandomAccessIterator>
|
849 | 832 | void __sort(_RandomAccessIterator, _RandomAccessIterator, _Comp);
|
850 | 833 |
|
@@ -878,7 +861,7 @@ template <class _AlgPolicy, class _RandomAccessIterator, class _Comp>
|
878 | 861 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
|
879 | 862 | __sort_dispatch(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp& __comp) {
|
880 | 863 | typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
|
881 |
| - difference_type __depth_limit = 2 * std::__log2i(__last - __first); |
| 864 | + difference_type __depth_limit = 2 * std::__bit_log2(std::__to_unsigned_like(__last - __first)); |
882 | 865 |
|
883 | 866 | // Only use bitset partitioning for arithmetic types. We should also check
|
884 | 867 | // that the default comparator is in use so that we are sure that there are no
|
|
0 commit comments