mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 22:00:09 +00:00
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:
parent
eb7368356d
commit
cb690e6698
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue