From 04a1ca69faa2e65d9e21cbcd6a18aeb792e70b9f Mon Sep 17 00:00:00 2001 From: Vaadin Bot Date: Fri, 7 Jan 2022 11:53:33 +0200 Subject: [PATCH] refactor: make isAttached iterative (#12665) (#12683) Since isAttached is trivially tail-recursive, use a loop instead of recursion. Reduces memory consumption in tests that construct deep trees. Co-authored-by: Johannes Eriksson --- .../main/java/com/vaadin/flow/internal/StateNode.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/flow-server/src/main/java/com/vaadin/flow/internal/StateNode.java b/flow-server/src/main/java/com/vaadin/flow/internal/StateNode.java index a3dc3644357..2dac3ec9ee4 100644 --- a/flow-server/src/main/java/com/vaadin/flow/internal/StateNode.java +++ b/flow-server/src/main/java/com/vaadin/flow/internal/StateNode.java @@ -567,7 +567,15 @@ public void markAsDirty() { * this node is not attached */ public boolean isAttached() { - return parent != null && parent.isAttached(); + if (getParent() == null) { + return false; + } else { + StateNode root = getParent(); + while (root.getParent() != null) { + root = root.getParent(); + } + return root.isAttached(); + } } /**