Skip to content

Commit 4446bf6

Browse files
committed
Simplify __bitset::__init
1 parent f53abc2 commit 4446bf6

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

libcxx/include/bitset

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -253,26 +253,16 @@ 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)
259-
if (__sz < __bits_per_word)
260-
__t[__i] = static_cast<__storage_type>(__v) & (1ULL << __sz) - 1;
261-
else
262-
__t[__i] = static_cast<__storage_type>(__v);
263-
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));
256+
const size_t __ull_words = sizeof(unsigned long long) / sizeof(__storage_type);
257+
for (size_t __i = 0; __i < __ull_words; ++__i, __v >>= __bits_per_word)
258+
__first_[__i] = static_cast<__storage_type>(__v);
259+
std::fill(__first_ + __ull_words, __first_ + _N_words, __storage_type(0));
267260
}
268261

269262
template <size_t _N_words, size_t _Size>
270263
inline _LIBCPP_HIDE_FROM_ABI void __bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT {
271264
__first_[0] = __v;
272-
if (_Size < __bits_per_word)
273-
__first_[0] &= (1ULL << _Size) - 1;
274-
275-
std::fill(__first_ + 1, __first_ + sizeof(__first_) / sizeof(__first_[0]), __storage_type(0));
265+
std::fill(__first_ + 1, __first_ + _N_words, __storage_type(0));
276266
}
277267

278268
# endif // _LIBCPP_CXX03_LANG

0 commit comments

Comments
 (0)