Author: Duncan P. N. Exon Smith Date: 2021-01-13T21:10:31-08:00 New Revision: 6ed3083a96541a7483cb02bb3b2f52b1d0a37c84
URL: https://github.com/llvm/llvm-project/commit/6ed3083a96541a7483cb02bb3b2f52b1d0a37c84 DIFF: https://github.com/llvm/llvm-project/commit/6ed3083a96541a7483cb02bb3b2f52b1d0a37c84.diff LOG: ADT: Reduce code duplication in SmallVector by calling reserve and clear, NFC Added: Modified: llvm/include/llvm/ADT/SmallVector.h Removed: ################################################################################ diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h index 0103798a9a6b7..b9c30abcb579e 100644 --- a/llvm/include/llvm/ADT/SmallVector.h +++ b/llvm/include/llvm/ADT/SmallVector.h @@ -603,9 +603,7 @@ class SmallVectorImpl : public SmallVectorTemplateBase<T> { 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<T>::swap(SmallVectorImpl<T> &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<T> &SmallVectorImpl<T>:: // 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<T> &SmallVectorImpl<T>::operator=(SmallVectorImpl<T> &&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) { _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits