From 7614a52ed46505cff135cc2a1a22116cd23ee970 Mon Sep 17 00:00:00 2001 From: Dmitry Batkovich Date: Fri, 1 Nov 2019 12:41:35 +0300 Subject: [PATCH] lazy creation of InspectionTreeNode$Children GitOrigin-RevId: 5c47bfc35c656949d84bd5308aca87237c9584e3 --- .../ui/InspectionTreeModel.java | 30 +++++++++---------- .../codeInspection/ui/InspectionTreeNode.java | 7 +++-- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTreeModel.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTreeModel.java index b5998f9b61f0..bc917259f0a3 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTreeModel.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTreeModel.java @@ -87,7 +87,10 @@ public class InspectionTreeModel extends BaseTreeModel imple InspectionTreeNode p = getParent(n1); int idx = getIndexOfChild(p, n1); if (idx < 0) return JBIterable.empty(); - InspectionTreeNode[] arr = p.myChildren.myChildren; + assert p != null; + InspectionTreeNode.Children children = p.myChildren; + if (children == null) return JBIterable.empty(); + InspectionTreeNode[] arr = children.myChildren; List sublist; if (direction) { sublist = Arrays.asList(arr).subList(idx + (n1 == node ? 0 : 1), arr.length); @@ -99,19 +102,6 @@ public class InspectionTreeModel extends BaseTreeModel imple }); } - public void removeChild(@NotNull InspectionTreeNode node, int childIndex) { - InspectionTreeNode removed = node.myChildren.myChildren[childIndex]; - remove(removed); - treeNodesChanged(null, null, null); - treeStructureChanged(null, null, null); - } - - public void removeChildren(@NotNull InspectionTreeNode node) { - doRemove(node, node); - treeNodesChanged(null, null, null); - treeStructureChanged(null, null, null); - } - public void remove(@NotNull InspectionTreeNode node) { doRemove(node, null); treeNodesChanged(null, null, null); @@ -126,6 +116,7 @@ public class InspectionTreeModel extends BaseTreeModel imple InspectionTreeNode parent = getParent(node); if (parent != null) { InspectionTreeNode.Children parentChildren = parent.myChildren; + assert parentChildren != null; parentChildren.myChildren = ArrayUtil.remove(parentChildren.myChildren, node); parentChildren.myUserObject2Node.removeValue(node); } @@ -133,7 +124,10 @@ public class InspectionTreeModel extends BaseTreeModel imple } synchronized void clearTree() { - myRoot.myChildren.clear(); + InspectionTreeNode.Children children = myRoot.myChildren; + if (children != null) { + children.clear(); + } } @NotNull @@ -198,11 +192,15 @@ public class InspectionTreeModel extends BaseTreeModel imple userObject = ObjectUtils.NULL; } InspectionTreeNode.Children children = parent.myChildren; + if (children == null) { + parent.myChildren = children = new InspectionTreeNode.Children(); + } InspectionTreeNode node = children.myUserObject2Node.get(userObject); if (node == null) { node = supplier.get(); InspectionTreeNode finalNode = node; - int idx = ReadAction.compute(() -> Arrays.binarySearch(children.myChildren, finalNode, InspectionResultsViewComparator.INSTANCE)); + InspectionTreeNode.Children finalChildren = children; + int idx = ReadAction.compute(() -> Arrays.binarySearch(finalChildren.myChildren, finalNode, InspectionResultsViewComparator.INSTANCE)); // it's allowed to have idx >= 0 for example for problem descriptor nodes. int insertionPoint = idx >= 0 ? idx : -idx - 1; children.myChildren = ArrayUtil.insert(children.myChildren, insertionPoint, node); diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTreeNode.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTreeNode.java index d741ecf06535..a5e94374deee 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTreeNode.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTreeNode.java @@ -35,8 +35,8 @@ public abstract class InspectionTreeNode implements TreeNode { }); protected final ProblemLevels myProblemLevels = new ProblemLevels(); - @NotNull - final Children myChildren = new Children(); + @Nullable + volatile Children myChildren; final InspectionTreeNode myParent; protected InspectionTreeNode(InspectionTreeNode parent) { @@ -141,7 +141,8 @@ public abstract class InspectionTreeNode implements TreeNode { @NotNull public List getChildren() { - return ContainerUtil.immutableList(myChildren.myChildren); + Children children = myChildren; + return children == null ? Collections.emptyList() : ContainerUtil.immutableList(children.myChildren); } @Override