forked from firka/flutter
Switched Element.renderObject to iterative implementation. (#112885)
This commit is contained in:
@@ -3418,19 +3418,22 @@ abstract class Element extends DiagnosticableTree implements BuildContext {
|
||||
/// this location in the tree. Otherwise, this getter will walk down the tree
|
||||
/// until it finds a [RenderObjectElement].
|
||||
RenderObject? get renderObject {
|
||||
RenderObject? result;
|
||||
void visit(Element element) {
|
||||
assert(result == null); // this verifies that there's only one child
|
||||
if (element._lifecycleState == _ElementLifecycle.defunct) {
|
||||
return;
|
||||
} else if (element is RenderObjectElement) {
|
||||
result = element.renderObject;
|
||||
Element? current = this;
|
||||
while (current != null) {
|
||||
if (current._lifecycleState == _ElementLifecycle.defunct) {
|
||||
break;
|
||||
} else if (current is RenderObjectElement) {
|
||||
return current.renderObject;
|
||||
} else {
|
||||
element.visitChildren(visit);
|
||||
Element? next;
|
||||
current.visitChildren((Element child) {
|
||||
assert(next == null); // This verifies that there's only one child.
|
||||
next = child;
|
||||
});
|
||||
current = next;
|
||||
}
|
||||
}
|
||||
visit(this);
|
||||
return result;
|
||||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user