From 6ccb54b0d34a2987d685ddb355065063d6f4c3af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Kr=C3=BCger?= Date: Mon, 1 Oct 2012 13:35:15 +0200 Subject: [PATCH] [Ast] GetNodeAt now searches from the end - since getting the start location is more efficient than getting the end location. --- ICSharpCode.NRefactory.CSharp/Ast/AstNode.cs | 40 ++++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/ICSharpCode.NRefactory.CSharp/Ast/AstNode.cs b/ICSharpCode.NRefactory.CSharp/Ast/AstNode.cs index c192c3ac59..c57e2b3222 100644 --- a/ICSharpCode.NRefactory.CSharp/Ast/AstNode.cs +++ b/ICSharpCode.NRefactory.CSharp/Ast/AstNode.cs @@ -652,11 +652,11 @@ namespace ICSharpCode.NRefactory.CSharp { AstNode result = null; AstNode node = this; - while (node.FirstChild != null) { - var child = node.FirstChild; - while (child != null && child.EndLocation <= location) - child = child.nextSibling; - if (child != null && child.StartLocation <= location) { + while (node.LastChild != null) { + var child = node.LastChild; + while (child != null && child.StartLocation > location) + child = child.prevSibling; + if (child != null && location < child.EndLocation) { if (pred == null || pred (child)) result = child; node = child; @@ -687,11 +687,11 @@ namespace ICSharpCode.NRefactory.CSharp { T result = null; AstNode node = this; - while (node.FirstChild != null) { - var child = node.FirstChild; - while (child != null && child.EndLocation <= location) - child = child.nextSibling; - if (child != null && child.StartLocation <= location) { + while (node.LastChild != null) { + var child = node.LastChild; + while (child != null && child.StartLocation > location) + child = child.prevSibling; + if (child != null && location < child.EndLocation) { if (child is T) result = (T)child; node = child; @@ -725,11 +725,11 @@ namespace ICSharpCode.NRefactory.CSharp { AstNode result = null; AstNode node = this; - while (node.FirstChild != null) { - var child = node.FirstChild; - while (child != null && child.EndLocation < location) - child = child.nextSibling; - if (child != null && child.StartLocation <= location) { + while (node.LastChild != null) { + var child = node.LastChild; + while (child != null && child.StartLocation > location) + child = child.prevSibling; + if (child != null && location <= child.EndLocation) { if (pred == null || pred (child)) result = child; node = child; @@ -760,11 +760,11 @@ namespace ICSharpCode.NRefactory.CSharp { T result = null; AstNode node = this; - while (node.FirstChild != null) { - var child = node.FirstChild; - while (child != null && child.EndLocation < location) - child = child.nextSibling; - if (child != null && child.StartLocation <= location) { + while (node.LastChild != null) { + var child = node.LastChild; + while (child != null && child.StartLocation > location) + child = child.prevSibling; + if (child != null && location <= child.EndLocation) { if (child is T) result = (T)child; node = child;