@@ -555,30 +555,20 @@ vector<bool, _Allocator>::__recommend(size_type __new_size) const {
555
555
template <class _Allocator >
556
556
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
557
557
vector<bool , _Allocator>::__construct_at_end(size_type __n, bool __x) {
558
- size_type __old_size = this -> __size_ ;
558
+ iterator __old_end = end () ;
559
559
this ->__size_ += __n;
560
- if (__old_size == 0 || ((__old_size - 1 ) / __bits_per_word) != ((this ->__size_ - 1 ) / __bits_per_word)) {
561
- if (this ->__size_ <= __bits_per_word)
562
- this ->__begin_ [0 ] = __storage_type (0 );
563
- else
564
- this ->__begin_ [(this ->__size_ - 1 ) / __bits_per_word] = __storage_type (0 );
565
- }
566
- std::fill_n (__make_iter (__old_size), __n, __x);
560
+ this ->__begin_ [(this ->__size_ - 1 ) / __bits_per_word] = __storage_type (0 );
561
+ std::fill_n (__old_end, __n, __x);
567
562
}
568
563
569
564
template <class _Allocator >
570
565
template <class _InputIterator , class _Sentinel >
571
566
_LIBCPP_CONSTEXPR_SINCE_CXX20 void
572
567
vector<bool , _Allocator>::__construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n) {
573
- size_type __old_size = this -> __size_ ;
568
+ iterator __old_end = end () ;
574
569
this ->__size_ += __n;
575
- if (__old_size == 0 || ((__old_size - 1 ) / __bits_per_word) != ((this ->__size_ - 1 ) / __bits_per_word)) {
576
- if (this ->__size_ <= __bits_per_word)
577
- this ->__begin_ [0 ] = __storage_type (0 );
578
- else
579
- this ->__begin_ [(this ->__size_ - 1 ) / __bits_per_word] = __storage_type (0 );
580
- }
581
- std::__copy (__first, __last, __make_iter (__old_size));
570
+ this ->__begin_ [(this ->__size_ - 1 ) / __bits_per_word] = __storage_type (0 );
571
+ std::__copy (__first, __last, __old_end);
582
572
}
583
573
584
574
template <class _Allocator >
@@ -852,7 +842,9 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::reserve(size_type _
852
842
this ->__throw_length_error ();
853
843
vector __v (this ->get_allocator ());
854
844
__v.__vallocate (__n);
855
- __v.__construct_at_end (this ->begin (), this ->end (), this ->size ());
845
+ // Ensure that the call to __construct_at_end(first, last, n) meets the precondition of n > 0
846
+ if (this ->size () > 0 )
847
+ __v.__construct_at_end (this ->begin (), this ->end (), this ->size ());
856
848
swap (__v);
857
849
}
858
850
}
0 commit comments