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

Chandler Carruth chandlerc at gmail.com
Tue Mar 4 01:00:15 PST 2014


Author: chandlerc
Date: Tue Mar  4 03:00:15 2014
New Revision: 202802

URL: http://llvm.org/viewvc/llvm-project?rev=202802&view=rev
Log:
[cleanup] Use early exit and simpler temporary variables to clarify the
swap implementation.

Modified:
    llvm/trunk/lib/IR/Use.cpp

Modified: llvm/trunk/lib/IR/Use.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Use.cpp?rev=202802&r1=202801&r2=202802&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Use.cpp (original)
+++ llvm/trunk/lib/IR/Use.cpp Tue Mar  4 03:00:15 2014
@@ -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;
   }
 }
 





More information about the llvm-commits mailing list