Skip to content

Commit

Permalink
Don't eliminate delegate caching when lambda decompilation is disabled.
Browse files Browse the repository at this point in the history
  • Loading branch information
dgrunwald committed May 10, 2013
1 parent a90cf65 commit d2c24a3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
12 changes: 7 additions & 5 deletions ICSharpCode.Decompiler/ILAst/ILAstOptimizer.cs
Expand Up @@ -225,11 +225,13 @@ public void Optimize(DecompilerContext context, ILBlock method, ILAstOptimizatio
new ILInlining(method).InlineAllVariables();

if (abortBeforeStep == ILAstOptimizationStep.CachedDelegateInitialization) return;
foreach(ILBlock block in method.GetSelfAndChildrenRecursive<ILBlock>()) {
for (int i = 0; i < block.Body.Count; i++) {
// TODO: Move before loops
CachedDelegateInitializationWithField(block, ref i);
CachedDelegateInitializationWithLocal(block, ref i);
if (context.Settings.AnonymousMethods) {
foreach(ILBlock block in method.GetSelfAndChildrenRecursive<ILBlock>()) {
for (int i = 0; i < block.Body.Count; i++) {
// TODO: Move before loops
CachedDelegateInitializationWithField(block, ref i);
CachedDelegateInitializationWithLocal(block, ref i);
}
}
}

Expand Down
16 changes: 16 additions & 0 deletions ICSharpCode.Decompiler/Tests/DelegateConstruction.cs
Expand Up @@ -62,6 +62,22 @@ public Action CaptureOfThisAndParameterInForEachWithItemCopy(int a)
}
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)
Expand Down

0 comments on commit d2c24a3

Please sign in to comment.