Skip to content

Commit

Permalink
refactor: make isAttached iterative
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 committed Jan 3, 2022
1 parent 0a0cbb5 commit d9f59af
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

/**
Expand Down

0 comments on commit d9f59af

Please sign in to comment.