Browse Source

Run a second pass of DetectExitPoints to use 'return;' as exit point if no previous transform picked another exit point.

This eliminates redundant 'return;' and 'yield break;' instructions.
pull/728/merge
Daniel Grunwald 9 years ago
parent
commit
f0e230ae91
  1. 2
      ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
  2. 5
      ICSharpCode.Decompiler/IL/ControlFlow/ExitPoints.cs

2
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -109,7 +109,7 @@ namespace ICSharpCode.Decompiler.CSharp
) )
} }
}, },
//new DetectExitPoints(canIntroduceExitForReturn: true), new DetectExitPoints(canIntroduceExitForReturn: true),
new DelegateConstruction(), new DelegateConstruction(),
}; };
} }

5
ICSharpCode.Decompiler/IL/ControlFlow/ExitPoints.cs

@ -167,6 +167,11 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
private bool CanIntroduceAsExit(ILInstruction inst) private bool CanIntroduceAsExit(ILInstruction inst)
{ {
if (currentContainer.LeaveCount > 0) {
// if we're re-running on a block container that already has an exit,
// we can't introduce any additional exits
return false;
}
if (inst is Leave l && l.IsLeavingFunction) { if (inst is Leave l && l.IsLeavingFunction) {
return canIntroduceExitForReturn; return canIntroduceExitForReturn;
} else { } else {

Loading…
Cancel
Save