From 775581c4181c7f5ef36258788ae19d6346d3f0ec Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Tue, 4 Mar 2014 09:00:15 +0000 Subject: [PATCH] [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 --- lib/IR/Use.cpp | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/lib/IR/Use.cpp b/lib/IR/Use.cpp index b6720e56764..5f01e238e04 100644 --- a/lib/IR/Use.cpp +++ b/lib/IR/Use.cpp @@ -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; } }