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 { ...@@ -3418,19 +3418,22 @@ abstract class Element extends DiagnosticableTree implements BuildContext {
/// this location in the tree. Otherwise, this getter will walk down the tree /// this location in the tree. Otherwise, this getter will walk down the tree
/// until it finds a [RenderObjectElement]. /// until it finds a [RenderObjectElement].
RenderObject? get renderObject { RenderObject? get renderObject {
RenderObject? result; Element? current = this;
void visit(Element element) { while (current != null) {
assert(result == null); // this verifies that there's only one child if (current._lifecycleState == _ElementLifecycle.defunct) {
if (element._lifecycleState == _ElementLifecycle.defunct) { break;
return; } else if (current is RenderObjectElement) {
} else if (element is RenderObjectElement) { return current.renderObject;
result = element.renderObject;
} else { } 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 null;
return result;
} }
@override @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