|
10 | 10 | #define _LIBCPP___VECTOR_VECTOR_BOOL_H
|
11 | 11 |
|
12 | 12 | #include <__algorithm/copy.h>
|
| 13 | +#include <__algorithm/fill.h> |
13 | 14 | #include <__algorithm/fill_n.h>
|
14 | 15 | #include <__algorithm/iterator_operations.h>
|
15 | 16 | #include <__algorithm/max.h>
|
@@ -536,30 +537,20 @@ vector<bool, _Allocator>::__recommend(size_type __new_size) const {
|
536 | 537 | template <class _Allocator>
|
537 | 538 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
|
538 | 539 | vector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x) {
|
539 |
| - size_type __old_size = this->__size_; |
| 540 | + iterator __old_end = end(); |
540 | 541 | this->__size_ += __n;
|
541 |
| - if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word)) { |
542 |
| - if (this->__size_ <= __bits_per_word) |
543 |
| - this->__begin_[0] = __storage_type(0); |
544 |
| - else |
545 |
| - this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0); |
546 |
| - } |
547 |
| - std::fill_n(__make_iter(__old_size), __n, __x); |
| 542 | + this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0); |
| 543 | + std::fill_n(__old_end, __n, __x); |
548 | 544 | }
|
549 | 545 |
|
550 | 546 | template <class _Allocator>
|
551 | 547 | template <class _InputIterator, class _Sentinel>
|
552 | 548 | _LIBCPP_CONSTEXPR_SINCE_CXX20 void
|
553 | 549 | vector<bool, _Allocator>::__construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n) {
|
554 |
| - size_type __old_size = this->__size_; |
| 550 | + iterator __old_end = end(); |
555 | 551 | this->__size_ += __n;
|
556 |
| - if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word)) { |
557 |
| - if (this->__size_ <= __bits_per_word) |
558 |
| - this->__begin_[0] = __storage_type(0); |
559 |
| - else |
560 |
| - this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0); |
561 |
| - } |
562 |
| - std::__copy(__first, __last, __make_iter(__old_size)); |
| 552 | + this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0); |
| 553 | + std::__copy(__first, __last, __old_end); |
563 | 554 | }
|
564 | 555 |
|
565 | 556 | template <class _Allocator>
|
@@ -833,7 +824,9 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::reserve(size_type _
|
833 | 824 | this->__throw_length_error();
|
834 | 825 | vector __v(this->get_allocator());
|
835 | 826 | __v.__vallocate(__n);
|
836 |
| - __v.__construct_at_end(this->begin(), this->end(), this->size()); |
| 827 | + // Ensure that the call to __construct_at_end(first, last, n) meets the precondition of n > 0 |
| 828 | + if (this->size() > 0) |
| 829 | + __v.__construct_at_end(this->begin(), this->end(), this->size()); |
837 | 830 | swap(__v);
|
838 | 831 | }
|
839 | 832 | }
|
|
0 commit comments