[libcxx-commits] [libcxx] [libc++][NFC] Reuse `__bit_log2` for `sort` (PR #135303)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Fri Apr 11 02:46:10 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)));
----------------
philnik777 wrote:

```suggestion
  difference_type __depth_limit = 2 * std::__bit_log2(std::__to_unsigned_like(__last - __first));
```


https://github.com/llvm/llvm-project/pull/135303


More information about the libcxx-commits mailing list