forked from OSchip/llvm-project
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:
parent
5c27740238
commit
36e7b8dd56
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue