diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h --- a/llvm/include/llvm/ADT/SmallVector.h +++ b/llvm/include/llvm/ADT/SmallVector.h @@ -460,19 +460,29 @@ this->Size = 0; } - void resize(size_type N) { +private: + template void resizeImpl(size_type N) { if (N < this->size()) { - this->destroy_range(this->begin()+N, this->end()); + this->destroy_range(this->begin() + N, this->end()); this->set_size(N); } else if (N > this->size()) { if (this->capacity() < N) this->grow(N); for (auto I = this->end(), E = this->begin() + N; I != E; ++I) - new (&*I) T(); + if (ForOverwrite) + new (&*I) T; + else + new (&*I) T(); this->set_size(N); } } +public: + void resize(size_type N) { resizeImpl(N); } + + /// Like resize, but \ref T is POD, the new values won't be initialized. + void resize_for_overwrite(size_type N) { resizeImpl(N); } + void resize(size_type N, const T &NV) { if (N == this->size()) return;