[llvm] 36e7b8d - ADT: Reduce nesting in resize_for_overwrite(), NFC
Duncan P. N. Exon Smith via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 8 12:51:56 PST 2021
Author: Duncan P. N. Exon Smith
Date: 2021-12-08T12:51:22-08:00
New Revision: 36e7b8dd564b383d9b4ca38674dbed6337e642b3
URL: https://github.com/llvm/llvm-project/commit/36e7b8dd564b383d9b4ca38674dbed6337e642b3
DIFF: https://github.com/llvm/llvm-project/commit/36e7b8dd564b383d9b4ca38674dbed6337e642b3.diff
LOG: ADT: Reduce nesting in resize_for_overwrite(), NFC
Use an early return in SmallVectorImpl::resize_for_overwite() to reduce
nesting. This also makes it easier to visually compare against the
two-argument version of resize().
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 0d13524f25ce0..1f511b549c131 100644
--- a/llvm/include/llvm/ADT/SmallVector.h
+++ b/llvm/include/llvm/ADT/SmallVector.h
@@ -589,17 +589,21 @@ class SmallVectorImpl : public SmallVectorTemplateBase<T> {
private:
template <bool ForOverwrite> void resizeImpl(size_type N) {
+ if (N == this->size())
+ return;
+
if (N < this->size()) {
this->pop_back_n(this->size() - N);
- } else if (N > this->size()) {
- this->reserve(N);
- for (auto I = this->end(), E = this->begin() + N; I != E; ++I)
- if (ForOverwrite)
- new (&*I) T;
- else
- new (&*I) T();
- this->set_size(N);
+ return;
}
+
+ this->reserve(N);
+ for (auto I = this->end(), E = this->begin() + N; I != E; ++I)
+ if (ForOverwrite)
+ new (&*I) T;
+ else
+ new (&*I) T();
+ this->set_size(N);
}
public:
More information about the llvm-commits
mailing list