[llvm] 91fe3e3 - ADT: Use early returns in SmallVector::resize, NFC
Duncan P. N. Exon Smith via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 19 17:30:21 PST 2020
Author: Duncan P. N. Exon Smith
Date: 2020-11-19T17:28:57-08:00
New Revision: 91fe3e309c7c4b2c7c906353e4b658ee704fe0bf
URL: https://github.com/llvm/llvm-project/commit/91fe3e309c7c4b2c7c906353e4b658ee704fe0bf
DIFF: https://github.com/llvm/llvm-project/commit/91fe3e309c7c4b2c7c906353e4b658ee704fe0bf.diff
LOG: ADT: Use early returns in SmallVector::resize, NFC
Just a simple cleanup, no functionality change here.
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 18463214df80..ed329aa02e34 100644
--- a/llvm/include/llvm/ADT/SmallVector.h
+++ b/llvm/include/llvm/ADT/SmallVector.h
@@ -462,16 +462,20 @@ class SmallVectorImpl : public SmallVectorTemplateBase<T> {
}
void resize(size_type N, const T &NV) {
+ if (N == this->size())
+ return;
+
if (N < this->size()) {
this->destroy_range(this->begin()+N, this->end());
this->set_size(N);
- } else if (N > this->size()) {
- this->assertSafeToReferenceAfterResize(&NV, N);
- if (this->capacity() < N)
- this->grow(N);
- std::uninitialized_fill(this->end(), this->begin()+N, NV);
- this->set_size(N);
+ return;
}
+
+ this->assertSafeToReferenceAfterResize(&NV, N);
+ if (this->capacity() < N)
+ this->grow(N);
+ std::uninitialized_fill(this->end(), this->begin() + N, NV);
+ this->set_size(N);
}
void reserve(size_type N) {
More information about the llvm-commits
mailing list