@@ -549,28 +549,29 @@ vector<bool, _Allocator>::__recommend(size_type __new_size) const {
549549}
550550
551551// Default constructs __n objects starting at __end_
552- // Precondition: __n > 0
553552// Precondition: size() + __n <= capacity()
554553// Postcondition: size() == size() + __n
555554template <class _Allocator >
556555inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
557556vector<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);
560560 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 );
563563}
564564
565565template <class _Allocator >
566566template <class _InputIterator , class _Sentinel >
567567_LIBCPP_CONSTEXPR_SINCE_CXX20 void
568568vector<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 ());
571572 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 );
574575}
575576
576577template <class _Allocator >
0 commit comments