From 46c99ddc44b27037ff2c721ec5f588f0c32589fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Srbeck=C3=BD?= Date: Sun, 27 Feb 2011 19:36:25 +0000 Subject: [PATCH] Performance improvement - use accumulator list for GetSelfAndChildrenRecursive --- ICSharpCode.Decompiler/ILAst/ILAstTypes.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler/ILAst/ILAstTypes.cs b/ICSharpCode.Decompiler/ILAst/ILAstTypes.cs index 7b4c5c82b..ec5aeb2b1 100644 --- a/ICSharpCode.Decompiler/ILAst/ILAstTypes.cs +++ b/ICSharpCode.Decompiler/ILAst/ILAstTypes.cs @@ -18,7 +18,19 @@ namespace Decompiler { public IEnumerable GetSelfAndChildrenRecursive() where T: ILNode { - return TreeTraversal.PreOrder(this, c => c != null ? c.GetChildren() : null).OfType(); + List result = new List(16); + AccumulateSelfAndChildrenRecursive(result); + return result; + } + + void AccumulateSelfAndChildrenRecursive(List 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 GetChildren()