Browse Source

Performance improvement - use accumulator list for GetSelfAndChildrenRecursive

pull/70/head
David Srbecký 15 years ago
parent
commit
46c99ddc44
  1. 14
      ICSharpCode.Decompiler/ILAst/ILAstTypes.cs

14
ICSharpCode.Decompiler/ILAst/ILAstTypes.cs

@ -18,7 +18,19 @@ namespace Decompiler @@ -18,7 +18,19 @@ namespace Decompiler
{
public IEnumerable<T> GetSelfAndChildrenRecursive<T>() where T: ILNode
{
return TreeTraversal.PreOrder(this, c => c != null ? c.GetChildren() : null).OfType<T>();
List<T> result = new List<T>(16);
AccumulateSelfAndChildrenRecursive(result);
return result;
}
void AccumulateSelfAndChildrenRecursive<T>(List<T> list) where T:ILNode
{
if (this is T)
list.Add((T)this);
foreach (ILNode node in this.GetChildren()) {
if (node != null)
node.AccumulateSelfAndChildrenRecursive(list);
}
}
public virtual IEnumerable<ILNode> GetChildren()

Loading…
Cancel
Save