optimization: insert element in proper position instead of sorting all nodes recursiv...
authornik <Nikolay.Chashnikov@jetbrains.com>
Tue, 7 Jul 2015 13:29:12 +0000 (16:29 +0300)
committernik <Nikolay.Chashnikov@jetbrains.com>
Wed, 8 Jul 2015 17:42:45 +0000 (20:42 +0300)
platform/platform-api/src/com/intellij/openapi/ui/MasterDetailsComponent.java

index cef3f1bb367cc8dfec68a5b14ba668cf9a0c2990..fc9d152df6603a3106c4de0acec157a80aa7bffe 100644 (file)
@@ -579,8 +579,9 @@ public abstract class MasterDetailsComponent implements Configurable, DetailsCom
   }
 
   protected void addNode(MyNode nodeToAdd, MyNode parent) {
-    parent.add(nodeToAdd);
-    sortDescendants(parent);
+    int i = TreeUtil.indexedBinarySearch(parent, nodeToAdd, getNodeComparator());
+    int insertionPoint = i >= 0 ? i : -i - 1;
+    ((DefaultTreeModel)myTree.getModel()).insertNodeInto(nodeToAdd, parent, insertionPoint);
   }
 
   protected void sortDescendants(MyNode root) {