Browse Source

[Ast] Optimized GetNodeAt methods.

newNRvisualizers
Mike Krüger 14 years ago
parent
commit
5b655b1fc1
  1. 48
      ICSharpCode.NRefactory.CSharp/Ast/AstNode.cs

48
ICSharpCode.NRefactory.CSharp/Ast/AstNode.cs

@ -654,19 +654,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -654,19 +654,17 @@ namespace ICSharpCode.NRefactory.CSharp
AstNode node = this;
while (node.FirstChild != null) {
var child = node.FirstChild;
while (child != null) {
if (child.StartLocation <= location && location < child.EndLocation) {
while (child != null && child.EndLocation <= location)
child = child.nextSibling;
if (child != null && child.StartLocation <= location) {
if (pred == null || pred (child))
result = child;
node = child;
break;
}
child = child.NextSibling;
}
} else {
// found no better child node - therefore the parent is the right one.
if (child == null)
break;
}
}
return result;
}
@ -691,19 +689,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -691,19 +689,17 @@ namespace ICSharpCode.NRefactory.CSharp
AstNode node = this;
while (node.FirstChild != null) {
var child = node.FirstChild;
while (child != null) {
if (child.StartLocation <= location && location < child.EndLocation) {
while (child != null && child.EndLocation <= location)
child = child.nextSibling;
if (child != null && child.StartLocation <= location) {
if (child is T)
result = (T)child;
node = child;
break;
}
child = child.NextSibling;
}
} else {
// found no better child node - therefore the parent is the right one.
if (child == null)
break;
}
}
return result;
}
@ -731,19 +727,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -731,19 +727,17 @@ namespace ICSharpCode.NRefactory.CSharp
AstNode node = this;
while (node.FirstChild != null) {
var child = node.FirstChild;
while (child != null) {
if (child.StartLocation <= location && location <= child.EndLocation) {
while (child != null && child.EndLocation < location)
child = child.nextSibling;
if (child != null && child.StartLocation <= location) {
if (pred == null || pred (child))
result = child;
node = child;
break;
}
child = child.NextSibling;
}
} else {
// found no better child node - therefore the parent is the right one.
if (child == null)
break;
}
}
return result;
}
@ -768,19 +762,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -768,19 +762,17 @@ namespace ICSharpCode.NRefactory.CSharp
AstNode node = this;
while (node.FirstChild != null) {
var child = node.FirstChild;
while (child != null) {
if (child.StartLocation <= location && location < child.EndLocation) {
while (child != null && child.EndLocation < location)
child = child.nextSibling;
if (child != null && child.StartLocation <= location) {
if (child is T)
result = (T)child;
node = child;
break;
}
child = child.NextSibling;
}
} else {
// found no better child node - therefore the parent is the right one.
if (child == null)
break;
}
}
return result;
}
#endregion

Loading…
Cancel
Save