[llvm] r206918 - No need to check condition after grow()

Rui Ueyama ruiu at google.com
Tue Apr 22 12:47:27 PDT 2014


Author: ruiu
Date: Tue Apr 22 14:47:26 2014
New Revision: 206918

URL: http://llvm.org/viewvc/llvm-project?rev=206918&view=rev
Log:
No need to check condition after grow()

r206916 was not logically the same as the previous code because the
goto statements did not create loop. This should be the same as the
previous code.


Modified:
    llvm/trunk/include/llvm/ADT/SmallVector.h

Modified: llvm/trunk/include/llvm/ADT/SmallVector.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/SmallVector.h?rev=206918&r1=206917&r2=206918&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/SmallVector.h (original)
+++ llvm/trunk/include/llvm/ADT/SmallVector.h Tue Apr 22 14:47:26 2014
@@ -223,14 +223,14 @@ protected:
   
 public:
   void push_back(const T &Elt) {
-    while (this->EndX >= this->CapacityX)
+    if (this->EndX >= this->CapacityX)
       this->grow();
     ::new ((void*) this->end()) T(Elt);
     this->setEnd(this->end()+1);
   }
 
   void push_back(T &&Elt) {
-    while (this->EndX >= this->CapacityX)
+    if (this->EndX >= this->CapacityX)
       this->grow();
     ::new ((void*) this->end()) T(::std::move(Elt));
     this->setEnd(this->end()+1);
@@ -327,7 +327,7 @@ protected:
   }
 public:
   void push_back(const T &Elt) {
-    while (this->EndX >= this->CapacityX)
+    if (this->EndX >= this->CapacityX)
       this->grow();
     memcpy(this->end(), &Elt, sizeof(T));
     this->setEnd(this->end()+1);
@@ -481,7 +481,7 @@ public:
     assert(I >= this->begin() && "Insertion iterator is out of bounds.");
     assert(I <= this->end() && "Inserting past the end of the vector.");
 
-    while (this->EndX >= this->CapacityX) {
+    if (this->EndX >= this->CapacityX) {
       size_t EltNo = I-this->begin();
       this->grow();
       I = this->begin()+EltNo;
@@ -511,7 +511,7 @@ public:
     assert(I >= this->begin() && "Insertion iterator is out of bounds.");
     assert(I <= this->end() && "Inserting past the end of the vector.");
 
-    while (this->EndX >= this->CapacityX) {
+    if (this->EndX >= this->CapacityX) {
       size_t EltNo = I-this->begin();
       this->grow();
       I = this->begin()+EltNo;





More information about the llvm-commits mailing list