Skip to content

Commit

Permalink
refactor: make isAttached iterative (#12665)
Browse files Browse the repository at this point in the history
Since isAttached is trivially tail-recursive, use a loop instead of recursion.
Reduces memory consumption in tests that construct deep trees.
  • Loading branch information
Johannes Eriksson authored and vaadin-bot committed Jan 7, 2022
1 parent 3b733c9 commit 113519f
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

/**
Expand Down

0 comments on commit 113519f

Please sign in to comment.