@@ -461,6 +461,15 @@ class _LIBCPP_TEMPLATE_VIS vector {
461
461
emplace_back (_Args&&... __args);
462
462
#endif
463
463
464
+ template <class ... _Args>
465
+ _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __emplace_back_assume_capacity (_Args&&... __args) {
466
+ _LIBCPP_ASSERT_INTERNAL (
467
+ size () < capacity (), " We assume that we have enough space to insert an element at the end of the vector" );
468
+ _ConstructTransaction __tx (*this , 1 );
469
+ __alloc_traits::construct (this ->__alloc_ , std::__to_address (__tx.__pos_ ), std::forward<_Args>(__args)...);
470
+ ++__tx.__pos_ ;
471
+ }
472
+
464
473
#if _LIBCPP_STD_VER >= 23
465
474
template <_ContainerCompatibleRange<_Tp> _Range>
466
475
_LIBCPP_HIDE_FROM_ABI constexpr void append_range (_Range&& __range) {
@@ -758,13 +767,6 @@ class _LIBCPP_TEMPLATE_VIS vector {
758
767
_ConstructTransaction& operator =(_ConstructTransaction const &) = delete ;
759
768
};
760
769
761
- template <class ... _Args>
762
- _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __construct_one_at_end (_Args&&... __args) {
763
- _ConstructTransaction __tx (*this , 1 );
764
- __alloc_traits::construct (this ->__alloc_ , std::__to_address (__tx.__pos_ ), std::forward<_Args>(__args)...);
765
- ++__tx.__pos_ ;
766
- }
767
-
768
770
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __base_destruct_at_end (pointer __new_last) _NOEXCEPT {
769
771
pointer __soon_to_be_end = this ->__end_ ;
770
772
while (__new_last != __soon_to_be_end)
@@ -1152,7 +1154,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 inline
1152
1154
vector<_Tp, _Allocator>::emplace_back (_Args&&... __args) {
1153
1155
pointer __end = this ->__end_ ;
1154
1156
if (__end < this ->__cap_ ) {
1155
- __construct_one_at_end (std::forward<_Args>(__args)...);
1157
+ __emplace_back_assume_capacity (std::forward<_Args>(__args)...);
1156
1158
++__end;
1157
1159
} else {
1158
1160
__end = __emplace_back_slow_path (std::forward<_Args>(__args)...);
@@ -1206,7 +1208,7 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
1206
1208
pointer __p = this ->__begin_ + (__position - begin ());
1207
1209
if (this ->__end_ < this ->__cap_ ) {
1208
1210
if (__p == this ->__end_ ) {
1209
- __construct_one_at_end (__x);
1211
+ __emplace_back_assume_capacity (__x);
1210
1212
} else {
1211
1213
__move_range (__p, this ->__end_ , __p + 1 );
1212
1214
const_pointer __xr = pointer_traits<const_pointer>::pointer_to (__x);
@@ -1228,7 +1230,7 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x) {
1228
1230
pointer __p = this ->__begin_ + (__position - begin ());
1229
1231
if (this ->__end_ < this ->__cap_ ) {
1230
1232
if (__p == this ->__end_ ) {
1231
- __construct_one_at_end (std::move (__x));
1233
+ __emplace_back_assume_capacity (std::move (__x));
1232
1234
} else {
1233
1235
__move_range (__p, this ->__end_ , __p + 1 );
1234
1236
*__p = std::move (__x);
@@ -1248,7 +1250,7 @@ vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args) {
1248
1250
pointer __p = this ->__begin_ + (__position - begin ());
1249
1251
if (this ->__end_ < this ->__cap_ ) {
1250
1252
if (__p == this ->__end_ ) {
1251
- __construct_one_at_end (std::forward<_Args>(__args)...);
1253
+ __emplace_back_assume_capacity (std::forward<_Args>(__args)...);
1252
1254
} else {
1253
1255
__temp_value<value_type, _Allocator> __tmp (this ->__alloc_ , std::forward<_Args>(__args)...);
1254
1256
__move_range (__p, this ->__end_ , __p + 1 );
@@ -1300,7 +1302,7 @@ vector<_Tp, _Allocator>::__insert_with_sentinel(const_iterator __position, _Inpu
1300
1302
pointer __p = this ->__begin_ + __off;
1301
1303
pointer __old_last = this ->__end_ ;
1302
1304
for (; this ->__end_ != this ->__cap_ && __first != __last; ++__first)
1303
- __construct_one_at_end (*__first);
1305
+ __emplace_back_assume_capacity (*__first);
1304
1306
1305
1307
if (__first == __last)
1306
1308
(void )std::rotate (__p, __old_last, this ->__end_ );
0 commit comments