@@ -549,28 +549,29 @@ vector<bool, _Allocator>::__recommend(size_type __new_size) const {
549
549
}
550
550
551
551
// Default constructs __n objects starting at __end_
552
- // Precondition: __n > 0
553
552
// Precondition: size() + __n <= capacity()
554
553
// Postcondition: size() == size() + __n
555
554
template <class _Allocator >
556
555
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
557
556
vector<bool , _Allocator>::__construct_at_end(size_type __n, bool __x) {
558
- _LIBCPP_ASSERT_INTERNAL (__n > 0 , " This function expects __n > 0" );
559
- iterator __old_end = end ();
557
+ _LIBCPP_ASSERT_INTERNAL (
558
+ capacity () >= size () + __n, " vector<bool>::__construct_at_end called with insufficient capacity" );
559
+ std::fill_n (end (), __n, __x);
560
560
this ->__size_ += __n;
561
- this -> __begin_ [( this -> __size_ - 1 ) / __bits_per_word] = __storage_type ( 0 );
562
- std::fill_n (__old_end, __n, __x );
561
+ if ( end (). __ctz_ != 0 ) // has uninitialized trailing bits in the last word
562
+ std::fill_n (end (), __bits_per_word - end (). __ctz_ , 0 );
563
563
}
564
564
565
565
template <class _Allocator >
566
566
template <class _InputIterator , class _Sentinel >
567
567
_LIBCPP_CONSTEXPR_SINCE_CXX20 void
568
568
vector<bool , _Allocator>::__construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n) {
569
- _LIBCPP_ASSERT_INTERNAL (__n > 0 , " This function expects __n > 0" );
570
- iterator __old_end = end ();
569
+ _LIBCPP_ASSERT_INTERNAL (
570
+ capacity () >= size () + __n, " vector<bool>::__construct_at_end called with insufficient capacity" );
571
+ std::__copy (__first, __last, end ());
571
572
this ->__size_ += __n;
572
- this -> __begin_ [( this -> __size_ - 1 ) / __bits_per_word] = __storage_type ( 0 );
573
- std::__copy (__first, __last, __old_end );
573
+ if ( end (). __ctz_ != 0 ) // has uninitialized trailing bits in the last word
574
+ std::fill_n ( end (), __bits_per_word - end (). __ctz_ , 0 );
574
575
}
575
576
576
577
template <class _Allocator >
0 commit comments