1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 11:02:59 +02:00

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.

llvm-svn: 206916
This commit is contained in:
Rui Ueyama 2014-04-22 19:07:14 +00:00
parent e6dc2fa469
commit 1717e7b0c5

View File

@ -223,25 +223,17 @@ protected:
public: public:
void push_back(const T &Elt) { void push_back(const T &Elt) {
if (this->EndX < this->CapacityX) { while (this->EndX >= this->CapacityX)
Retry: this->grow();
::new ((void*) this->end()) T(Elt); ::new ((void*) this->end()) T(Elt);
this->setEnd(this->end()+1); this->setEnd(this->end()+1);
return;
}
this->grow();
goto Retry;
} }
void push_back(T &&Elt) { void push_back(T &&Elt) {
if (this->EndX < this->CapacityX) { while (this->EndX >= this->CapacityX)
Retry: this->grow();
::new ((void*) this->end()) T(::std::move(Elt)); ::new ((void*) this->end()) T(::std::move(Elt));
this->setEnd(this->end()+1); this->setEnd(this->end()+1);
return;
}
this->grow();
goto Retry;
} }
void pop_back() { void pop_back() {
@ -335,14 +327,10 @@ protected:
} }
public: public:
void push_back(const T &Elt) { void push_back(const T &Elt) {
if (this->EndX < this->CapacityX) { while (this->EndX >= this->CapacityX)
Retry: this->grow();
memcpy(this->end(), &Elt, sizeof(T)); memcpy(this->end(), &Elt, sizeof(T));
this->setEnd(this->end()+1); this->setEnd(this->end()+1);
return;
}
this->grow();
goto Retry;
} }
void pop_back() { void pop_back() {
@ -493,26 +481,25 @@ public:
assert(I >= this->begin() && "Insertion iterator is out of bounds."); assert(I >= this->begin() && "Insertion iterator is out of bounds.");
assert(I <= this->end() && "Inserting past the end of the vector."); assert(I <= this->end() && "Inserting past the end of the vector.");
if (this->EndX < this->CapacityX) { while (this->EndX >= this->CapacityX) {
Retry: size_t EltNo = I-this->begin();
::new ((void*) this->end()) T(::std::move(this->back())); this->grow();
this->setEnd(this->end()+1); I = this->begin()+EltNo;
// 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.
T *EltPtr = &Elt;
if (I <= EltPtr && EltPtr < this->EndX)
++EltPtr;
*I = ::std::move(*EltPtr);
return I;
} }
size_t EltNo = I-this->begin();
this->grow(); ::new ((void*) this->end()) T(::std::move(this->back()));
I = this->begin()+EltNo; this->setEnd(this->end()+1);
goto Retry; // 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.
T *EltPtr = &Elt;
if (I <= EltPtr && EltPtr < this->EndX)
++EltPtr;
*I = ::std::move(*EltPtr);
return I;
} }
iterator insert(iterator I, const T &Elt) { 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->begin() && "Insertion iterator is out of bounds.");
assert(I <= this->end() && "Inserting past the end of the vector."); assert(I <= this->end() && "Inserting past the end of the vector.");
if (this->EndX < this->CapacityX) { while (this->EndX >= this->CapacityX) {
Retry: size_t EltNo = I-this->begin();
::new ((void*) this->end()) T(this->back()); this->grow();
this->setEnd(this->end()+1); I = this->begin()+EltNo;
// 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;
} }
size_t EltNo = I-this->begin(); ::new ((void*) this->end()) T(this->back());
this->grow(); this->setEnd(this->end()+1);
I = this->begin()+EltNo; // Push everything else over.
goto Retry; 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) { iterator insert(iterator I, size_type NumToInsert, const T &Elt) {