Browse Source

[Ast] Optimized GetNodeAt methods.

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

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

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

Loading…
Cancel
Save