Revert "Refactor ARM subarchitecture parsing"
[oota-llvm.git] / include / llvm / ADT / SmallVector.h
index 0a4140e8f8221041324cab0aab58f6e608f5c968..82538e9bd1085adebc212b1c001ceac8fef06d1d 100644 (file)
@@ -220,28 +220,20 @@ protected:
   /// Guarantees space for at least one more element, or MinSize more
   /// elements if specified.
   void grow(size_t MinSize = 0);
-  
+
 public:
   void push_back(const T &Elt) {
-    if (this->EndX < this->CapacityX) {
-    Retry:
-      ::new ((void*) this->end()) T(Elt);
-      this->setEnd(this->end()+1);
-      return;
-    }
-    this->grow();
-    goto Retry;
+    if (LLVM_UNLIKELY(this->EndX >= this->CapacityX))
+      this->grow();
+    ::new ((void*) this->end()) T(Elt);
+    this->setEnd(this->end()+1);
   }
 
   void push_back(T &&Elt) {
-    if (this->EndX < this->CapacityX) {
-    Retry:
-      ::new ((void*) this->end()) T(::std::move(Elt));
-      this->setEnd(this->end()+1);
-      return;
-    }
-    this->grow();
-    goto Retry;
+    if (LLVM_UNLIKELY(this->EndX >= this->CapacityX))
+      this->grow();
+    ::new ((void*) this->end()) T(::std::move(Elt));
+    this->setEnd(this->end()+1);
   }
 
   void pop_back() {
@@ -255,7 +247,7 @@ template <typename T, bool isPodLike>
 void SmallVectorTemplateBase<T, isPodLike>::grow(size_t MinSize) {
   size_t CurCapacity = this->capacity();
   size_t CurSize = this->size();
-  // Always grow, even from zero.  
+  // Always grow, even from zero.
   size_t NewCapacity = size_t(NextPowerOf2(CurCapacity+2));
   if (NewCapacity < MinSize)
     NewCapacity = MinSize;
@@ -335,16 +327,12 @@ protected:
   }
 public:
   void push_back(const T &Elt) {
-    if (this->EndX < this->CapacityX) {
-    Retry:
-      memcpy(this->end(), &Elt, sizeof(T));
-      this->setEnd(this->end()+1);
-      return;
-    }
-    this->grow();
-    goto Retry;
+    if (LLVM_UNLIKELY(this->EndX >= this->CapacityX))
+      this->grow();
+    memcpy(this->end(), &Elt, sizeof(T));
+    this->setEnd(this->end()+1);
   }
-  
+
   void pop_back() {
     this->setEnd(this->end()-1);
   }
@@ -392,7 +380,8 @@ public:
     } else if (N > this->size()) {
       if (this->capacity() < N)
         this->grow(N);
-      std::uninitialized_fill(this->end(), this->begin()+N, T());
+      for (auto I = this->end(), E = this->begin() + N; I != E; ++I)
+        new (&*I) T();
       this->setEnd(this->begin()+N);
     }
   }
@@ -493,26 +482,25 @@ public:
     assert(I >= this->begin() && "Insertion iterator is out of bounds.");
     assert(I <= this->end() && "Inserting past the end of the vector.");
 
-    if (this->EndX < this->CapacityX) {
-    Retry:
-      ::new ((void*) this->end()) T(::std::move(this->back()));
-      this->setEnd(this->end()+1);
-      // Push everything else over.
-      this->move_backward(I, this->end()-1, this->end());
+    if (this->EndX >= this->CapacityX) {
+      size_t EltNo = I-this->begin();
+      this->grow();
+      I = this->begin()+EltNo;
+    }
 
-      // If we just moved the element we're inserting, be sure to update
-      // the reference.
-      T *EltPtr = &Elt;
-      if (I <= EltPtr && EltPtr < this->EndX)
-        ++EltPtr;
+    ::new ((void*) this->end()) T(::std::move(this->back()));
+    // Push everything else over.
+    this->move_backward(I, this->end()-1, this->end());
+    this->setEnd(this->end()+1);
 
-      *I = ::std::move(*EltPtr);
-      return I;
-    }
-    size_t EltNo = I-this->begin();
-    this->grow();
-    I = this->begin()+EltNo;
-    goto Retry;
+    // If we just moved the element we're inserting, be sure to update
+    // the reference.
+    T *EltPtr = &Elt;
+    if (I <= EltPtr && EltPtr < this->EndX)
+      ++EltPtr;
+
+    *I = ::std::move(*EltPtr);
+    return I;
   }
 
   iterator insert(iterator I, const T &Elt) {
@@ -524,26 +512,24 @@ public:
     assert(I >= this->begin() && "Insertion iterator is out of bounds.");
     assert(I <= this->end() && "Inserting past the end of the vector.");
 
-    if (this->EndX < this->CapacityX) {
-    Retry:
-      ::new ((void*) this->end()) T(this->back());
-      this->setEnd(this->end()+1);
-      // Push everything else over.
-      this->move_backward(I, this->end()-1, this->end());
-
-      // If we just moved the element we're inserting, be sure to update
-      // the reference.
-      const T *EltPtr = &Elt;
-      if (I <= EltPtr && EltPtr < this->EndX)
-        ++EltPtr;
-
-      *I = *EltPtr;
-      return I;
+    if (this->EndX >= this->CapacityX) {
+      size_t EltNo = I-this->begin();
+      this->grow();
+      I = this->begin()+EltNo;
     }
-    size_t EltNo = I-this->begin();
-    this->grow();
-    I = this->begin()+EltNo;
-    goto Retry;
+    ::new ((void*) this->end()) T(std::move(this->back()));
+    // Push everything else over.
+    this->move_backward(I, this->end()-1, this->end());
+    this->setEnd(this->end()+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->EndX)
+      ++EltPtr;
+
+    *I = *EltPtr;
+    return I;
   }
 
   iterator insert(iterator I, size_type NumToInsert, const T &Elt) {
@@ -570,7 +556,8 @@ public:
     // reallocate the vector.
     if (size_t(this->end()-I) >= NumToInsert) {
       T *OldEnd = this->end();
-      append(this->end()-NumToInsert, this->end());
+      append(std::move_iterator<iterator>(this->end() - NumToInsert),
+             std::move_iterator<iterator>(this->end()));
 
       // Copy the existing elements that get replaced.
       this->move_backward(I, OldEnd-NumToInsert, OldEnd);
@@ -623,7 +610,8 @@ public:
     // reallocate the vector.
     if (size_t(this->end()-I) >= NumToInsert) {
       T *OldEnd = this->end();
-      append(this->end()-NumToInsert, this->end());
+      append(std::move_iterator<iterator>(this->end() - NumToInsert),
+             std::move_iterator<iterator>(this->end()));
 
       // Copy the existing elements that get replaced.
       this->move_backward(I, OldEnd-NumToInsert, OldEnd);
@@ -820,7 +808,7 @@ SmallVectorImpl<T> &SmallVectorImpl<T>::operator=(SmallVectorImpl<T> &&RHS) {
     this->grow(RHSSize);
   } else if (CurSize) {
     // Otherwise, use assignment for the already-constructed elements.
-    this->move(RHS.begin(), RHS.end(), this->begin());
+    this->move(RHS.begin(), RHS.begin()+CurSize, this->begin());
   }
 
   // Move-construct the new elements in place.