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

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