Skip to content

Commit c7e9b49

Browse files
mtezychmordante
andauthored
[libc++][vector] Inline remaining constructors filling vector with the same value (#82068)
Placing physically next to each other remaining constructors filling vector with the same value will make code better, since they all have nearly identical implementation, which needs to be kept in sync. Co-authored-by: Mark de Wever <koraq@xs4all.nl>
1 parent 89c23f7 commit c7e9b49

File tree

1 file changed

+28
-36
lines changed

1 file changed

+28
-36
lines changed

libcxx/include/vector

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -424,11 +424,36 @@ public:
424424
#endif
425425
: __end_cap_(nullptr, __a) {
426426
}
427-
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit vector(size_type __n);
427+
428+
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit vector(size_type __n) {
429+
auto __guard = std::__make_exception_guard(__destroy_vector(*this));
430+
if (__n > 0) {
431+
__vallocate(__n);
432+
__construct_at_end(__n);
433+
}
434+
__guard.__complete();
435+
}
436+
428437
#if _LIBCPP_STD_VER >= 14
429-
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit vector(size_type __n, const allocator_type& __a);
438+
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit vector(size_type __n, const allocator_type& __a)
439+
: __end_cap_(nullptr, __a) {
440+
auto __guard = std::__make_exception_guard(__destroy_vector(*this));
441+
if (__n > 0) {
442+
__vallocate(__n);
443+
__construct_at_end(__n);
444+
}
445+
__guard.__complete();
446+
}
430447
#endif
431-
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(size_type __n, const value_type& __x);
448+
449+
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(size_type __n, const value_type& __x) {
450+
auto __guard = std::__make_exception_guard(__destroy_vector(*this));
451+
if (__n > 0) {
452+
__vallocate(__n);
453+
__construct_at_end(__n, __x);
454+
}
455+
__guard.__complete();
456+
}
432457

433458
template <__enable_if_t<__is_allocator<_Allocator>::value, int> = 0>
434459
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
@@ -1125,39 +1150,6 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::__append(size_type _
11251150
}
11261151
}
11271152

1128-
template <class _Tp, class _Allocator>
1129-
_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(size_type __n) {
1130-
auto __guard = std::__make_exception_guard(__destroy_vector(*this));
1131-
if (__n > 0) {
1132-
__vallocate(__n);
1133-
__construct_at_end(__n);
1134-
}
1135-
__guard.__complete();
1136-
}
1137-
1138-
#if _LIBCPP_STD_VER >= 14
1139-
template <class _Tp, class _Allocator>
1140-
_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a)
1141-
: __end_cap_(nullptr, __a) {
1142-
auto __guard = std::__make_exception_guard(__destroy_vector(*this));
1143-
if (__n > 0) {
1144-
__vallocate(__n);
1145-
__construct_at_end(__n);
1146-
}
1147-
__guard.__complete();
1148-
}
1149-
#endif
1150-
1151-
template <class _Tp, class _Allocator>
1152-
_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x) {
1153-
auto __guard = std::__make_exception_guard(__destroy_vector(*this));
1154-
if (__n > 0) {
1155-
__vallocate(__n);
1156-
__construct_at_end(__n, __x);
1157-
}
1158-
__guard.__complete();
1159-
}
1160-
11611153
template <class _Tp, class _Allocator>
11621154
template <class _InputIterator,
11631155
__enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&

0 commit comments

Comments
 (0)