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
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 != null && child.StartLocation <= location) {
if (pred == null || pred (child)) if (pred == null || pred (child))
result = child; result = child;
node = child; node = child;
break; } 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,19 +689,17 @@ 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 != null && child.StartLocation <= location) {
if (child is T) if (child is T)
result = (T)child; result = (T)child;
node = child; node = child;
break; } 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,19 +727,17 @@ 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 != null && child.StartLocation <= location) {
if (pred == null || pred (child)) if (pred == null || pred (child))
result = child; result = child;
node = child; node = child;
break; } 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,19 +762,17 @@ 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 != null && child.StartLocation <= location) {
if (child is T) if (child is T)
result = (T)child; result = (T)child;
node = child; node = child;
break; } 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;
} }
#endregion #endregion

Loading…
Cancel
Save