diff --git a/platform/platform-api/src/com/intellij/util/ui/tree/TreeUtil.java b/platform/platform-api/src/com/intellij/util/ui/tree/TreeUtil.java index 29f22ff89639..d3e281010192 100644 --- a/platform/platform-api/src/com/intellij/util/ui/tree/TreeUtil.java +++ b/platform/platform-api/src/com/intellij/util/ui/tree/TreeUtil.java @@ -192,13 +192,22 @@ public final class TreeUtil { @NotNull public static TreePath getPathFromRoot(@NotNull TreeNode node) { - final ArrayList path = new ArrayList(); - do { - path.add(node); - node = node.getParent(); - } while (node != null); - Collections.reverse(path); - return new TreePath(path.toArray()); + TreeNode[] path = getPathFromRoot(node, 1); + return new TreePath(path); + } + + @NotNull + private static TreeNode[] getPathFromRoot(@NotNull TreeNode node, int depth) { + TreeNode[] path; + TreeNode parent = node.getParent(); + if (parent == null) { + path = new TreeNode[depth]; + } + else { + path = getPathFromRoot(parent, depth + 1); + } + path[path.length - depth] = node; + return path; } @Nullable