summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2014-04-22 19:07:14 +0000
committerRui Ueyama <ruiu@google.com>2014-04-22 19:07:14 +0000
commit8dd58d1f02be8e172b4b54fb0a724bb82b01963f (patch)
tree3c1ebe86ee5948ee36b2b49ccd55485af289af41 /include
parentb95412cc24e99a72ee3efc05a14995bb508f3a23 (diff)
downloadllvm-8dd58d1f02be8e172b4b54fb0a724bb82b01963f.tar.gz
llvm-8dd58d1f02be8e172b4b54fb0a724bb82b01963f.tar.bz2
llvm-8dd58d1f02be8e172b4b54fb0a724bb82b01963f.tar.xz
Replace loops using goto with plain while loops
Goto statements jumping into previous inner blocks are pretty confusing to read even though in this case they are valid. No reason to not use while loops there. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206916 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/ADT/SmallVector.h107
1 files changed, 46 insertions, 61 deletions
diff --git a/include/llvm/ADT/SmallVector.h b/include/llvm/ADT/SmallVector.h
index 0a4140e8f8..2409ecf9b6 100644
--- a/include/llvm/ADT/SmallVector.h
+++ b/include/llvm/ADT/SmallVector.h
@@ -223,25 +223,17 @@ protected:
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;
+ while (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;
+ while (this->EndX >= this->CapacityX)
+ this->grow();
+ ::new ((void*) this->end()) T(::std::move(Elt));
+ this->setEnd(this->end()+1);
}
void pop_back() {
@@ -335,14 +327,10 @@ 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;
+ while (this->EndX >= this->CapacityX)
+ this->grow();
+ memcpy(this->end(), &Elt, sizeof(T));
+ this->setEnd(this->end()+1);
}
void pop_back() {
@@ -493,26 +481,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());
+ while (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()));
+ this->setEnd(this->end()+1);
+ // Push everything else over.
+ this->move_backward(I, this->end()-1, this->end());
- *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 +511,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;
+ while (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(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;
}
iterator insert(iterator I, size_type NumToInsert, const T &Elt) {