[libcxx-commits] [libcxx] Simplify flip() for std::bit_set (PR #120807)
Peng Liu via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Dec 20 15:22:42 PST 2024
https://github.com/winner245 created https://github.com/llvm/llvm-project/pull/120807
This PR simplifies the `flip()` implementation for `std::bit_set` by unifying the internal processing of whole words and partial words.
>From fc7c189f769a2ddbce945e83a69ad32f3bb0861d Mon Sep 17 00:00:00 2001
From: Peng Liu <winner245 at hotmail.com>
Date: Fri, 20 Dec 2024 18:18:00 -0500
Subject: [PATCH] Simplify flip() for std::bit_set
---
libcxx/include/bitset | 14 ++------------
1 file changed, 2 insertions(+), 12 deletions(-)
diff --git a/libcxx/include/bitset b/libcxx/include/bitset
index e2dc7b459f1c4a..2ee7755c21fc95 100644
--- a/libcxx/include/bitset
+++ b/libcxx/include/bitset
@@ -319,18 +319,8 @@ __bitset<_N_words, _Size>::operator^=(const __bitset& __v) _NOEXCEPT {
template <size_t _N_words, size_t _Size>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void __bitset<_N_words, _Size>::flip() _NOEXCEPT {
- // do middle whole words
- size_type __n = _Size;
- __storage_pointer __p = __first_;
- 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;
- }
+ for (size_type __i = 0; __i < _N_words; ++__i)
+ __first_[__i] = ~__first_[__i];
}
template <size_t _N_words, size_t _Size>
More information about the libcxx-commits
mailing list