Skip to content

Commit d3e4f6f

Browse files
committed
Simplify vector<bool>::__construct_at_end
1 parent 0cbdad4 commit d3e4f6f

File tree

1 file changed

+14
-35
lines changed

1 file changed

+14
-35
lines changed

libcxx/include/__vector/vector_bool.h

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -438,10 +438,22 @@ class _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator> {
438438
return (__new_size + (__bits_per_word - 1)) & ~((size_type)__bits_per_word - 1);
439439
}
440440
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type __recommend(size_type __new_size) const;
441-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __construct_at_end(size_type __n, bool __x);
441+
442+
// Default constructs __n objects starting at __end_
443+
// Precondition: __n > 0
444+
// Precondition: size() + __n <= capacity()
445+
// Postcondition: size() == size() + __n
446+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __construct_at_end(size_type __n, bool __x) {
447+
std::fill_n(end(), __n, __x);
448+
this->__size_ += __n;
449+
}
442450
template <class _InputIterator, class _Sentinel>
443451
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
444-
__construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n);
452+
__construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n) {
453+
std::__copy(__first, __last, end());
454+
this->__size_ += __n;
455+
}
456+
445457
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __append(size_type __n, const_reference __x);
446458
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference __make_ref(size_type __pos) _NOEXCEPT {
447459
return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);
@@ -530,39 +542,6 @@ vector<bool, _Allocator>::__recommend(size_type __new_size) const {
530542
return std::max(2 * __cap, __align_it(__new_size));
531543
}
532544

533-
// Default constructs __n objects starting at __end_
534-
// Precondition: __n > 0
535-
// Precondition: size() + __n <= capacity()
536-
// Postcondition: size() == size() + __n
537-
template <class _Allocator>
538-
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
539-
vector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x) {
540-
size_type __old_size = this->__size_;
541-
this->__size_ += __n;
542-
if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word)) {
543-
if (this->__size_ <= __bits_per_word)
544-
this->__begin_[0] = __storage_type(0);
545-
else
546-
this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0);
547-
}
548-
std::fill_n(__make_iter(__old_size), __n, __x);
549-
}
550-
551-
template <class _Allocator>
552-
template <class _InputIterator, class _Sentinel>
553-
_LIBCPP_CONSTEXPR_SINCE_CXX20 void
554-
vector<bool, _Allocator>::__construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n) {
555-
size_type __old_size = this->__size_;
556-
this->__size_ += __n;
557-
if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word)) {
558-
if (this->__size_ <= __bits_per_word)
559-
this->__begin_[0] = __storage_type(0);
560-
else
561-
this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0);
562-
}
563-
std::__copy(__first, __last, __make_iter(__old_size));
564-
}
565-
566545
template <class _Allocator>
567546
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector()
568547
_NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)

0 commit comments

Comments
 (0)