Browse Source

Clean up RemoveDeadVariableInit

pull/900/head
Siegfried Pammer 8 years ago
parent
commit
aa87169331
  1. 4
      ICSharpCode.Decompiler/IL/Transforms/RemoveDeadVariableInit.cs

4
ICSharpCode.Decompiler/IL/Transforms/RemoveDeadVariableInit.cs

@ -44,7 +44,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
// This is necessary to remove useless stores generated by some compilers, e.g., the F# compiler. // This is necessary to remove useless stores generated by some compilers, e.g., the F# compiler.
// In yield return + async, the C# compiler tends to store null/default(T) to variables // In yield return + async, the C# compiler tends to store null/default(T) to variables
// when the variable goes out of scope. // when the variable goes out of scope.
var variableQueue = new Queue<ILVariable>(function.Variables.Where(v => v.Kind == VariableKind.Local || v.Kind == VariableKind.StackSlot)); var variableQueue = new Queue<ILVariable>(function.Variables);
while (variableQueue.Count > 0) { while (variableQueue.Count > 0) {
var v = variableQueue.Dequeue(); var v = variableQueue.Dequeue();
if (v.Kind != VariableKind.Local && v.Kind != VariableKind.StackSlot) if (v.Kind != VariableKind.Local && v.Kind != VariableKind.StackSlot)
@ -58,7 +58,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
} else { } else {
stloc.ReplaceWith(stloc.Value); stloc.ReplaceWith(stloc.Value);
} }
if (stloc.Value is LdLoc ldloc && (ldloc.Variable.Kind == VariableKind.Local || ldloc.Variable.Kind == VariableKind.StackSlot)) { if (stloc.Value is LdLoc ldloc) {
variableQueue.Enqueue(ldloc.Variable); variableQueue.Enqueue(ldloc.Variable);
} }
} }

Loading…
Cancel
Save