[libcxx-commits] [libcxx] [libc++][NFC] Reuse `__bit_log2` for `sort` (PR #135303)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Apr 11 02:58:58 PDT 2025
================
@@ -878,7 +861,8 @@ template <class _AlgPolicy, class _RandomAccessIterator, class _Comp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
__sort_dispatch(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp& __comp) {
typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
- difference_type __depth_limit = 2 * std::__log2i(__last - __first);
+ difference_type __depth_limit = static_cast<difference_type>(
+ 2 * std::__bit_log2(static_cast<__make_unsigned_t<difference_type> >(__last - __first)));
----------------
frederick-vs-ja wrote:
Oh, thanks! I was confused by the _`to-unsigned-like`_ in the standard wording which only is present since C++20.
https://github.com/llvm/llvm-project/pull/135303
More information about the libcxx-commits
mailing list