diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h index 0103798a9a6b7c..b9c30abcb579e3 100644 --- a/llvm/include/llvm/ADT/SmallVector.h +++ b/llvm/include/llvm/ADT/SmallVector.h @@ -603,9 +603,7 @@ class SmallVectorImpl : public SmallVectorTemplateBase { void append(in_iter in_start, in_iter in_end) { this->assertSafeToAddRange(in_start, in_end); size_type NumInputs = std::distance(in_start, in_end); - if (NumInputs > this->capacity() - this->size()) - this->grow(this->size()+NumInputs); - + this->reserve(this->size() + NumInputs); this->uninitialized_copy(in_start, in_end, this->end()); this->set_size(this->size() + NumInputs); } @@ -888,10 +886,8 @@ void SmallVectorImpl::swap(SmallVectorImpl &RHS) { std::swap(this->Capacity, RHS.Capacity); return; } - if (RHS.size() > this->capacity()) - this->grow(RHS.size()); - if (this->size() > RHS.capacity()) - RHS.grow(this->size()); + this->reserve(RHS.size()); + RHS.reserve(this->size()); // Swap the shared elements. size_t NumShared = this->size(); @@ -946,8 +942,7 @@ SmallVectorImpl &SmallVectorImpl:: // FIXME: don't do this if they're efficiently moveable. if (this->capacity() < RHSSize) { // Destroy current elements. - this->destroy_range(this->begin(), this->end()); - this->set_size(0); + this->clear(); CurSize = 0; this->grow(RHSSize); } else if (CurSize) { @@ -1006,8 +1001,7 @@ SmallVectorImpl &SmallVectorImpl::operator=(SmallVectorImpl &&RHS) { // elements. if (this->capacity() < RHSSize) { // Destroy current elements. - this->destroy_range(this->begin(), this->end()); - this->set_size(0); + this->clear(); CurSize = 0; this->grow(RHSSize); } else if (CurSize) {