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 @@ -533,9 +533,10 @@ return(N); } - iterator insert(iterator I, T &&Elt) { +private: + template iterator insert_one_impl(iterator I, ArgType &&Elt) { if (I == this->end()) { // Important special case for empty vector. - this->push_back(::std::move(Elt)); + this->push_back(::std::forward(Elt)); return this->end()-1; } @@ -555,43 +556,21 @@ // If we just moved the element we're inserting, be sure to update // the reference. - T *EltPtr = &Elt; + std::remove_reference_t *EltPtr = &Elt; if (I <= EltPtr && EltPtr < this->end()) ++EltPtr; - *I = ::std::move(*EltPtr); + *I = ::std::forward(*EltPtr); return I; } - iterator insert(iterator I, const T &Elt) { - if (I == this->end()) { // Important special case for empty vector. - this->push_back(Elt); - return this->end()-1; - } - - assert(I >= this->begin() && "Insertion iterator is out of bounds."); - assert(I <= this->end() && "Inserting past the end of the vector."); - - if (this->size() >= this->capacity()) { - size_t EltNo = I-this->begin(); - this->grow(); - I = this->begin()+EltNo; - } - ::new ((void*) this->end()) T(std::move(this->back())); - // Push everything else over. - std::move_backward(I, this->end()-1, this->end()); - this->set_size(this->size() + 1); - - // If we just moved the element we're inserting, be sure to update - // the reference. - const T *EltPtr = &Elt; - if (I <= EltPtr && EltPtr < this->end()) - ++EltPtr; - - *I = *EltPtr; - return I; +public: + iterator insert(iterator I, T &&Elt) { + return insert_one_impl(I, std::move(Elt)); } + iterator insert(iterator I, const T &Elt) { return insert_one_impl(I, Elt); } + iterator insert(iterator I, size_type NumToInsert, const T &Elt) { // Convert iterator to elt# to avoid invalidating iterator when we reserve() size_t InsertElt = I - this->begin();