@@ -699,14 +699,7 @@ template <class _Allocator>
699699_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool , _Allocator>& vector<bool , _Allocator>::operator =(const vector& __v) {
700700 if (this != std::addressof (__v)) {
701701 __copy_assign_alloc (__v);
702- if (__v.__size_ ) {
703- if (__v.__size_ > capacity ()) {
704- __vdeallocate ();
705- __vallocate (__v.__size_ );
706- }
707- std::copy (__v.__begin_ , __v.__begin_ + __external_cap_to_internal (__v.__size_ ), __begin_);
708- }
709- __size_ = __v.__size_ ;
702+ __assign_with_size (__v.begin (), __v.end (), __v.size ());
710703 }
711704 return *this ;
712705}
@@ -773,19 +766,14 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::__move_assign(vecto
773766
774767template <class _Allocator >
775768_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool , _Allocator>::assign(size_type __n, const value_type& __x) {
776- __size_ = 0 ;
777769 if (__n > 0 ) {
778- size_type __c = capacity ();
779- if (__n <= __c)
780- __size_ = __n;
781- else {
782- vector __v (get_allocator ());
783- __v.reserve (__recommend (__n));
784- __v.__size_ = __n;
785- swap (__v);
770+ if (__n > capacity ()) {
771+ __vdeallocate ();
772+ __vallocate (__n);
786773 }
787774 std::fill_n (begin (), __n, __x);
788775 }
776+ this ->__size_ = __n;
789777}
790778
791779template <class _Allocator >
@@ -814,17 +802,15 @@ template <class _ForwardIterator, class _Sentinel>
814802_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
815803vector<bool , _Allocator>::__assign_with_size(_ForwardIterator __first, _Sentinel __last, difference_type __ns) {
816804 _LIBCPP_ASSERT_VALID_INPUT_RANGE (__ns >= 0 , " invalid range specified" );
817-
818- clear ();
819-
820- const size_t __n = static_cast <size_type>(__ns);
805+ const size_type __n = static_cast <size_type>(__ns);
821806 if (__n) {
822807 if (__n > capacity ()) {
823808 __vdeallocate ();
824809 __vallocate (__n);
825810 }
826- __construct_at_end (__first, __last, __n );
811+ std::__copy (__first, __last, this -> begin () );
827812 }
813+ this ->__size_ = __n;
828814}
829815
830816template <class _Allocator >
0 commit comments