Commit 6ed3083a authored by Duncan P. N. Exon Smith's avatar Duncan P. N. Exon Smith
Browse files

ADT: Reduce code duplication in SmallVector by calling reserve and clear, NFC

parent 53b34601
Loading
Loading
Loading
Loading
+5 −11
Original line number Diff line number Diff line
@@ -603,9 +603,7 @@ public:
  void append(in_iter in_start, in_iter in_end) {
    this->assertSafeToAddRange(in_start, in_end);
    size_type NumInputs = std::distance(in_start, in_end);
    if (NumInputs > this->capacity() - this->size())
      this->grow(this->size()+NumInputs);

    this->reserve(this->size() + NumInputs);
    this->uninitialized_copy(in_start, in_end, this->end());
    this->set_size(this->size() + NumInputs);
  }
@@ -888,10 +886,8 @@ void SmallVectorImpl<T>::swap(SmallVectorImpl<T> &RHS) {
    std::swap(this->Capacity, RHS.Capacity);
    return;
  }
  if (RHS.size() > this->capacity())
    this->grow(RHS.size());
  if (this->size() > RHS.capacity())
    RHS.grow(this->size());
  this->reserve(RHS.size());
  RHS.reserve(this->size());

  // Swap the shared elements.
  size_t NumShared = this->size();
@@ -946,8 +942,7 @@ SmallVectorImpl<T> &SmallVectorImpl<T>::
  // FIXME: don't do this if they're efficiently moveable.
  if (this->capacity() < RHSSize) {
    // Destroy current elements.
    this->destroy_range(this->begin(), this->end());
    this->set_size(0);
    this->clear();
    CurSize = 0;
    this->grow(RHSSize);
  } else if (CurSize) {
@@ -1006,8 +1001,7 @@ SmallVectorImpl<T> &SmallVectorImpl<T>::operator=(SmallVectorImpl<T> &&RHS) {
  // elements.
  if (this->capacity() < RHSSize) {
    // Destroy current elements.
    this->destroy_range(this->begin(), this->end());
    this->set_size(0);
    this->clear();
    CurSize = 0;
    this->grow(RHSSize);
  } else if (CurSize) {