@@ -699,14 +699,7 @@ template <class _Allocator>
699
699
_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool , _Allocator>& vector<bool , _Allocator>::operator =(const vector& __v) {
700
700
if (this != std::addressof (__v)) {
701
701
__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 ());
710
703
}
711
704
return *this ;
712
705
}
@@ -754,7 +747,7 @@ vector<bool, _Allocator>::operator=(vector&& __v)
754
747
template <class _Allocator >
755
748
_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool , _Allocator>::__move_assign(vector& __c, false_type) {
756
749
if (__alloc_ != __c.__alloc_ )
757
- assign (__c.begin (), __c.end ());
750
+ __assign_with_size (__c.begin (), __c.end (), __c. size ());
758
751
else
759
752
__move_assign (__c, true_type ());
760
753
}
@@ -773,19 +766,14 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::__move_assign(vecto
773
766
774
767
template <class _Allocator >
775
768
_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool , _Allocator>::assign(size_type __n, const value_type& __x) {
776
- __size_ = 0 ;
777
769
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);
786
773
}
787
774
std::fill_n (begin (), __n, __x);
788
775
}
776
+ this ->__size_ = __n;
789
777
}
790
778
791
779
template <class _Allocator >
@@ -814,17 +802,15 @@ template <class _ForwardIterator, class _Sentinel>
814
802
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
815
803
vector<bool , _Allocator>::__assign_with_size(_ForwardIterator __first, _Sentinel __last, difference_type __ns) {
816
804
_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);
821
806
if (__n) {
822
807
if (__n > capacity ()) {
823
808
__vdeallocate ();
824
809
__vallocate (__n);
825
810
}
826
- __construct_at_end (__first, __last, __n );
811
+ std::__copy (__first, __last, this -> begin () );
827
812
}
813
+ this ->__size_ = __n;
828
814
}
829
815
830
816
template <class _Allocator >
0 commit comments