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().
This commit is contained in:
Duncan P. N. Exon Smith 2021-12-07 16:16:45 -08:00
parent 5c27740238
commit 36e7b8dd56
1 changed files with 12 additions and 8 deletions

View File

@ -589,17 +589,21 @@ public:
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: