From d9f59af8c2cd686780ea0e280ff34ec51799316c Mon Sep 17 00:00:00 2001 From: Johannes Eriksson Date: Mon, 3 Jan 2022 15:34:56 +0200 Subject: [PATCH] refactor: make isAttached iterative Since isAttached is trivially tail-recursive, use a loop instead of recursion. Reduces memory consumption in tests that construct deep trees. --- .../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 9a4e75d60d3..ad911cf5967 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 @@ -574,7 +574,15 @@ public void markAsDirty() { * this node is not attached */ public boolean isAttached() { - return parent != null && parent.isAttached(); + if (getParent() == null) { + return false; + } else { + StateNode current = getParent(); + while (current.getParent() != null) { + current = current.getParent(); + } + return current.isAttached(); + } } /**