Skip to content

Commit

Permalink
Duplicate return statement with const int/bool.
Browse files Browse the repository at this point in the history
  • Loading branch information
dsrbecky committed Feb 27, 2011
1 parent 46c99dd commit 3f4578f
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions ICSharpCode.Decompiler/ILAst/ILAstOptimizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,15 +354,18 @@ void DuplicateReturnStatements(ILBlock method)
// Inline return statement
ILNode target;
ILExpression retExpr;
ILVariable locVar = null;
if (nextSibling.TryGetValue(targetLabel, out target) &&
target.Match(ILCode.Ret, out retExpr) &&
(retExpr.Arguments.Count == 0 || retExpr.Arguments.Single().Match(ILCode.Ldloc, out locVar)))
target.Match(ILCode.Ret, out retExpr))
{
ILExpression dup = new ILExpression(ILCode.Ret, null);
if (locVar != null)
dup.Arguments = new List<ILExpression>() { new ILExpression(ILCode.Ldloc, locVar) };
block.Body[i] = dup;
ILVariable locVar;
object constValue;
if (retExpr.Arguments.Count == 0) {
block.Body[i] = new ILExpression(ILCode.Ret, null);
} else if (retExpr.Arguments.Single().Match(ILCode.Ldloc, out locVar)) {
block.Body[i] = new ILExpression(ILCode.Ret, null, new ILExpression(ILCode.Ldloc, locVar));
} else if (retExpr.Arguments.Single().Match(ILCode.Ldc_I4, out constValue)) {
block.Body[i] = new ILExpression(ILCode.Ret, null, new ILExpression(ILCode.Ldc_I4, constValue));
}
}
}
}
Expand Down

0 comments on commit 3f4578f

Please sign in to comment.