[llvm] r202802 - [cleanup] Use early exit and simpler temporary variables to clarify the
David Blaikie
dblaikie at gmail.com
Tue Mar 4 08:21:12 PST 2014
On Tue, Mar 4, 2014 at 1:00 AM, Chandler Carruth <chandlerc at gmail.com> wrote:
> 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.
As an aside (not a priority): Do you reckon most of the clients of
swap really just want/need move assignment? I imagine move assignment
would be a little easier/clearer to implement (but maybe not much?),
and just implement swap in terms of move would be only a slight
pessimization of swap (which would only be an issue if clients
/really/ care about swap perf, rather than just wanting move
assignment)?
> 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;
> }
> }
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list