@@ -664,9 +664,6 @@ class vector {
664664 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
665665 __construct_at_end (_InputIterator __first, _Sentinel __last, size_type __n);
666666
667- _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __append (size_type __n);
668- _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __append (size_type __n, const_reference __x);
669-
670667 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator __make_iter (pointer __p) _NOEXCEPT {
671668#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS_IN_VECTOR
672669 // Bound the iterator according to the capacity, rather than the size.
@@ -971,36 +968,6 @@ vector<_Tp, _Allocator>::__construct_at_end(_InputIterator __first, _Sentinel __
971968 __tx.__pos_ = std::__uninitialized_allocator_copy (this ->__alloc_ , std::move (__first), std::move (__last), __tx.__pos_ );
972969}
973970
974- // Default constructs __n objects starting at __end_
975- // throws if construction throws
976- // Postcondition: size() == size() + __n
977- // Exception safety: strong.
978- template <class _Tp , class _Allocator >
979- _LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::__append(size_type __n) {
980- if (static_cast <size_type>(this ->__cap_ - this ->__end_ ) >= __n)
981- this ->__construct_at_end (__n);
982- else {
983- __split_buffer<value_type, allocator_type&> __v (__recommend (size () + __n), size (), this ->__alloc_ );
984- __v.__construct_at_end (__n);
985- __swap_out_circular_buffer (__v);
986- }
987- }
988-
989- // Default constructs __n objects starting at __end_
990- // throws if construction throws
991- // Postcondition: size() == size() + __n
992- // Exception safety: strong.
993- template <class _Tp , class _Allocator >
994- _LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x) {
995- if (static_cast <size_type>(this ->__cap_ - this ->__end_ ) >= __n)
996- this ->__construct_at_end (__n, __x);
997- else {
998- __split_buffer<value_type, allocator_type&> __v (__recommend (size () + __n), size (), this ->__alloc_ );
999- __v.__construct_at_end (__n, __x);
1000- __swap_out_circular_buffer (__v);
1001- }
1002- }
1003-
1004971template <class _Tp , class _Allocator >
1005972_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI vector<_Tp, _Allocator>::vector(vector&& __x)
1006973#if _LIBCPP_STD_VER >= 17
@@ -1402,21 +1369,35 @@ vector<_Tp, _Allocator>::__insert_with_size(
14021369}
14031370
14041371template <class _Tp , class _Allocator >
1405- _LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::resize (size_type __sz) {
1406- size_type __cs = size ();
1407- if (__cs < __sz)
1408- this ->__append (__sz - __cs);
1409- else if (__cs > __sz)
1410- this ->__destruct_at_end (this ->__begin_ + __sz);
1372+ _LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::resize (size_type __new_size) {
1373+ size_type __current_size = size ();
1374+ if (__current_size < __new_size) {
1375+ if (__new_size <= capacity ()) {
1376+ __construct_at_end (__new_size - __current_size);
1377+ } else {
1378+ __split_buffer<value_type, allocator_type&> __v (__recommend (__new_size), __current_size, __alloc_);
1379+ __v.__construct_at_end (__new_size - __current_size);
1380+ __swap_out_circular_buffer (__v);
1381+ }
1382+ } else if (__current_size > __new_size) {
1383+ this ->__destruct_at_end (this ->__begin_ + __new_size);
1384+ }
14111385}
14121386
14131387template <class _Tp , class _Allocator >
1414- _LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::resize (size_type __sz, const_reference __x) {
1415- size_type __cs = size ();
1416- if (__cs < __sz)
1417- this ->__append (__sz - __cs, __x);
1418- else if (__cs > __sz)
1419- this ->__destruct_at_end (this ->__begin_ + __sz);
1388+ _LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::resize (size_type __new_size, const_reference __x) {
1389+ size_type __current_size = size ();
1390+ if (__current_size < __new_size) {
1391+ if (__new_size <= capacity ())
1392+ __construct_at_end (__new_size - __current_size, __x);
1393+ else {
1394+ __split_buffer<value_type, allocator_type&> __v (__recommend (__new_size), __current_size, __alloc_);
1395+ __v.__construct_at_end (__new_size - __current_size, __x);
1396+ __swap_out_circular_buffer (__v);
1397+ }
1398+ } else if (__current_size > __new_size) {
1399+ this ->__destruct_at_end (this ->__begin_ + __new_size);
1400+ }
14201401}
14211402
14221403template <class _Tp , class _Allocator >
0 commit comments