Optimize thisOrAncestorOfType

Closes https://github.com/dart-lang/sdk/pull/53288

GitOrigin-RevId: 8fcdfaf9f6d64be0c91bdd49a57d64a516cf0778
Change-Id: Ic49d50594464fd1d7eccc6c1c98627d7854bc3e9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/321840
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Graciliano Monteiro Passos 2023-08-21 16:58:46 +00:00 committed by Commit Queue
parent eb7368356d
commit cb690e6698

View file

@ -2422,15 +2422,13 @@ abstract class ElementImpl implements Element {
@override
E? thisOrAncestorOfType<E extends Element>() {
Element? element = this;
while (element != null && element is! E) {
if (element is CompilationUnitElement) {
element = element.enclosingElement;
} else {
element = element.enclosingElement;
}
Element element = this;
while (element is! E) {
var ancestor = element.enclosingElement;
if (ancestor == null) return null;
element = ancestor ;
}
return element as E?;
return element;
}
@override