[libcxx-commits] [libcxx] Simplify flip() for std::bitset (PR #120807)
Peng Liu via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Feb 19 15:55:35 PST 2025
================
@@ -327,12 +327,8 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void __bitset<_N_words, _Siz
for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
*__p = ~*__p;
// do last partial word
- if (__n > 0) {
- __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
- __storage_type __b = *__p & __m;
- *__p &= ~__m;
- *__p |= ~__b & __m;
- }
+ if (__n > 0)
+ *__p ^= (__storage_type(1) << __n) - 1;
----------------
winner245 wrote:
Thanks! I've added a comment explaining this.
https://github.com/llvm/llvm-project/pull/120807
More information about the libcxx-commits
mailing list