Unverified Commit 69fc4fb6 authored by gaaclarke's avatar gaaclarke Committed by GitHub

Switched `Element.renderObject` to iterative implementation. (#112885)

parent c7b40a52
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment