mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
lazy creation of InspectionTreeNode$Children
GitOrigin-RevId: 5c47bfc35c656949d84bd5308aca87237c9584e3
This commit is contained in:
committed by
intellij-monorepo-bot
parent
6c0a6ec337
commit
7614a52ed4
@@ -87,7 +87,10 @@ public class InspectionTreeModel extends BaseTreeModel<InspectionTreeNode> 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<? extends InspectionTreeNode> sublist;
|
||||
if (direction) {
|
||||
sublist = Arrays.asList(arr).subList(idx + (n1 == node ? 0 : 1), arr.length);
|
||||
@@ -99,19 +102,6 @@ public class InspectionTreeModel extends BaseTreeModel<InspectionTreeNode> 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<InspectionTreeNode> 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<InspectionTreeNode> 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<InspectionTreeNode> 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);
|
||||
|
||||
@@ -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<? extends InspectionTreeNode> getChildren() {
|
||||
return ContainerUtil.immutableList(myChildren.myChildren);
|
||||
Children children = myChildren;
|
||||
return children == null ? Collections.emptyList() : ContainerUtil.immutableList(children.myChildren);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user