Browse Source

Don't eliminate delegate caching when lambda decompilation is disabled.

Closes #388
pull/402/merge
Daniel Grunwald 12 years ago
parent
commit
d2c24a3b0a
  1. 2
      ICSharpCode.Decompiler/ILAst/ILAstOptimizer.cs
  2. 16
      ICSharpCode.Decompiler/Tests/DelegateConstruction.cs

2
ICSharpCode.Decompiler/ILAst/ILAstOptimizer.cs

@ -225,6 +225,7 @@ namespace ICSharpCode.Decompiler.ILAst
new ILInlining(method).InlineAllVariables(); new ILInlining(method).InlineAllVariables();
if (abortBeforeStep == ILAstOptimizationStep.CachedDelegateInitialization) return; if (abortBeforeStep == ILAstOptimizationStep.CachedDelegateInitialization) return;
if (context.Settings.AnonymousMethods) {
foreach(ILBlock block in method.GetSelfAndChildrenRecursive<ILBlock>()) { foreach(ILBlock block in method.GetSelfAndChildrenRecursive<ILBlock>()) {
for (int i = 0; i < block.Body.Count; i++) { for (int i = 0; i < block.Body.Count; i++) {
// TODO: Move before loops // TODO: Move before loops
@ -232,6 +233,7 @@ namespace ICSharpCode.Decompiler.ILAst
CachedDelegateInitializationWithLocal(block, ref i); CachedDelegateInitializationWithLocal(block, ref i);
} }
} }
}
if (abortBeforeStep == ILAstOptimizationStep.IntroduceFixedStatements) return; if (abortBeforeStep == ILAstOptimizationStep.IntroduceFixedStatements) return;
// we need post-order traversal, not pre-order, for "fixed" to work correctly // we need post-order traversal, not pre-order, for "fixed" to work correctly

16
ICSharpCode.Decompiler/Tests/DelegateConstruction.cs

@ -62,6 +62,22 @@ public static class DelegateConstruction
} }
return null; return null;
} }
public void LambdaInForLoop()
{
for (int i = 0; i < 100000; i++) {
Bar(() => Foo());
}
}
public int Foo()
{
return 0;
}
public void Bar(Func<int> f)
{
}
} }
public static void Test(this string a) public static void Test(this string a)

Loading…
Cancel
Save