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

This commit is contained in:
gaaclarke
2022-10-05 10:49:24 -07:00
committed by GitHub
parent c7b40a5270
commit 69fc4fb622

View File

@@ -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