Skip to content

Commit 48a787a

Browse files
committed
Unconditionally flip the last word
1 parent ff2f948 commit 48a787a

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

libcxx/include/__vector/vector_bool.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,14 +1049,11 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::resize(size_type __
10491049

10501050
template <class _Allocator>
10511051
_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::flip() _NOEXCEPT {
1052-
// Process the whole words in the front
1053-
size_type __n = __size_;
1052+
// Flip each storage word entirely, including the last potentially partial word.
1053+
// The unused bits in the last word are safe to flip as they won't be accessed.
10541054
__storage_pointer __p = __begin_;
1055-
for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
1055+
for (size_type __n = __external_cap_to_internal(size()); __n; ++__p, --__n)
10561056
*__p = ~*__p;
1057-
// Process the last partial word, if it exists
1058-
if (__n > 0)
1059-
*__p ^= ~__storage_type(0) >> (__bits_per_word - __n);
10601057
}
10611058

10621059
template <class _Allocator>

0 commit comments

Comments
 (0)