[cleanup] Use early exit and simpler temporary variables to clarify the

swap implementation.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202802 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chandler Carruth 2014-03-04 09:00:15 +00:00
parent 4f6b2a26da
commit 775581c418

View File

@ -14,27 +14,26 @@
namespace llvm {
void Use::swap(Use &RHS) {
Value *V1(Val);
Value *V2(RHS.Val);
if (V1 != V2) {
if (V1) {
removeFromList();
}
if (Val == RHS.Val)
return;
if (V2) {
RHS.removeFromList();
Val = V2;
V2->addUse(*this);
} else {
Val = 0;
}
if (Val)
removeFromList();
if (V1) {
RHS.Val = V1;
V1->addUse(RHS);
} else {
RHS.Val = 0;
}
Value *OldVal = Val;
if (RHS.Val) {
RHS.removeFromList();
Val = RHS.Val;
Val->addUse(*this);
} else {
Val = 0;
}
if (OldVal) {
RHS.Val = OldVal;
RHS.Val->addUse(RHS);
} else {
RHS.Val = 0;
}
}