[libcxx-commits] [libcxx] [libc++] Improve bitset::to_ullong Implementation (PR #121348)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Dec 30 19:06:08 PST 2024
================
@@ -381,8 +382,9 @@ __bitset<_N_words, _Size>::to_ullong(true_type, true_type) const {
unsigned long long __r = __first_[0];
_LIBCPP_DIAGNOSTIC_PUSH
_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wshift-count-overflow")
- for (size_t __i = 1; __i < sizeof(unsigned long long) / sizeof(__storage_type); ++__i)
- __r |= static_cast<unsigned long long>(__first_[__i]) << (sizeof(__storage_type) * CHAR_BIT);
+ size_t __n_words = std::min<size_t>(_N_words, sizeof(unsigned long long) / sizeof(__storage_type));
----------------
frederick-vs-ja wrote:
I think we want the newly introduced `__n_words` to be a constant expression.
How about this?
```suggestion
const size_t __ull_words = sizeof(unsigned long long) / sizeof(__storage_type);
const size_t __n_words = _N_words < __ull_words ? _N_words : __ull_words;
```
https://github.com/llvm/llvm-project/pull/121348
More information about the libcxx-commits
mailing list