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. 12
      ICSharpCode.Decompiler/ILAst/ILAstOptimizer.cs
  2. 16
      ICSharpCode.Decompiler/Tests/DelegateConstruction.cs

12
ICSharpCode.Decompiler/ILAst/ILAstOptimizer.cs

@ -225,11 +225,13 @@ namespace ICSharpCode.Decompiler.ILAst @@ -225,11 +225,13 @@ namespace ICSharpCode.Decompiler.ILAst
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);
}
}
}

16
ICSharpCode.Decompiler/Tests/DelegateConstruction.cs

@ -62,6 +62,22 @@ public static class DelegateConstruction @@ -62,6 +62,22 @@ public static class DelegateConstruction
}
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)

Loading…
Cancel
Save