Skip to content

Commit 71d07fd

Browse files
committed
Simplify __bitset::__init
1 parent 6230f1b commit 71d07fd

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

libcxx/include/bitset

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -253,17 +253,14 @@ inline _LIBCPP_CONSTEXPR __bitset<_N_words, _Size>::__bitset() _NOEXCEPT
253253

254254
template <size_t _N_words, size_t _Size>
255255
void __bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT {
256-
__storage_type __t[sizeof(unsigned long long) / sizeof(__storage_type)];
257-
size_t __sz = _Size;
258-
for (size_t __i = 0; __i < sizeof(__t) / sizeof(__t[0]); ++__i, __v >>= __bits_per_word, __sz -= __bits_per_word)
256+
size_t __ull = sizeof(unsigned long long) / sizeof(__storage_type);
257+
for (size_t __i = 0, __sz = _Size; __i < __ull; ++__i, __v >>= __bits_per_word, __sz -= __bits_per_word)
259258
if (__sz < __bits_per_word)
260-
__t[__i] = static_cast<__storage_type>(__v) & (1ULL << __sz) - 1;
259+
__first_[__i] = static_cast<__storage_type>(__v) & (1ULL << __sz) - 1;
261260
else
262-
__t[__i] = static_cast<__storage_type>(__v);
261+
__first_[__i] = static_cast<__storage_type>(__v);
263262

264-
std::copy(__t, __t + sizeof(__t) / sizeof(__t[0]), __first_);
265-
std::fill(
266-
__first_ + sizeof(__t) / sizeof(__t[0]), __first_ + sizeof(__first_) / sizeof(__first_[0]), __storage_type(0));
263+
std::fill(__first_ + __ull, __first_ + _N_words, __storage_type(0));
267264
}
268265

269266
template <size_t _N_words, size_t _Size>
@@ -272,7 +269,7 @@ inline _LIBCPP_HIDE_FROM_ABI void __bitset<_N_words, _Size>::__init(unsigned lon
272269
if (_Size < __bits_per_word)
273270
__first_[0] &= (1ULL << _Size) - 1;
274271

275-
std::fill(__first_ + 1, __first_ + sizeof(__first_) / sizeof(__first_[0]), __storage_type(0));
272+
std::fill(__first_ + 1, __first_ + _N_words, __storage_type(0));
276273
}
277274

278275
# endif // _LIBCPP_CXX03_LANG

0 commit comments

Comments
 (0)