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 @@ -1226,7 +1226,25 @@ } SmallVector &operator=(SmallVector &&RHS) { - SmallVectorImpl::operator=(::std::move(RHS)); + if (N) { + SmallVectorImpl::operator=(::std::move(RHS)); + return *this; + } + // SmallVectorImpl::operator= does not leverage N==0. Optimize the + // case. + if (this == &RHS) + return *this; + this->destroy_range(this->begin(), this->end()); + if (RHS.empty()) { + this->Size = 0; + } else { + if (!this->isSmall()) + free(this->begin()); + this->BeginX = RHS.BeginX; + this->Size = RHS.Size; + this->Capacity = RHS.Capacity; + RHS.resetToSmall(); + } return *this; }