Browse Source

Improve foreach-on-array detection with captured itemVariable.

pull/925/merge
Siegfried Pammer 8 years ago
parent
commit
c77dfb9100
  1. 3
      ICSharpCode.Decompiler/CSharp/Transforms/PatternStatementTransform.cs

3
ICSharpCode.Decompiler/CSharp/Transforms/PatternStatementTransform.cs

@ -251,7 +251,8 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms @@ -251,7 +251,8 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
var itemVariable = m.Get<IdentifierExpression>("itemVariable").Single().GetILVariable();
var indexVariable = m.Get<IdentifierExpression>("indexVariable").Single().GetILVariable();
var arrayVariable = m.Get<IdentifierExpression>("arrayVariable").Single().GetILVariable();
if (!itemVariable.IsSingleDefinition || itemVariable.CaptureScope != null)
var loopContainer = forStatement.Annotation<IL.BlockContainer>();
if (!itemVariable.IsSingleDefinition || (itemVariable.CaptureScope != null && itemVariable.CaptureScope != loopContainer))
return null;
if (indexVariable.StoreCount != 2 || indexVariable.LoadCount != 3 || indexVariable.AddressCount != 0)
return null;

Loading…
Cancel
Save