Skip to content

Commit

Permalink
[performance] Tree expand in reverse order - eclipse.platform.swt#901
Browse files Browse the repository at this point in the history
  • Loading branch information
EcljpseB0T authored and jukzi committed Dec 6, 2023
1 parent ac8883f commit 5930a51
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
Expand Up @@ -46,6 +46,7 @@
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Item;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.swt.widgets.Widget;

Expand Down Expand Up @@ -362,8 +363,9 @@ private void createAddedElements(Widget widget, Object[] elements) {

// Optimize for the empty case
if (items.length == 0) {
for (Object element : elements) {
createTreeItem(widget, element, -1);
// For performance insert every item at index 0 (in reverse order):
for (int i = elements.length - 1; i >= 0; i--) {
createTreeItem(widget, elements[i], 0);
}
return;
}
Expand Down Expand Up @@ -846,8 +848,9 @@ void createChildren(final Widget widget, boolean materialize) {
} else {
children = getSortedChildren(parentElement);
}
for (Object element : children) {
createTreeItem(widget, element, -1);
// For performance insert every item at index 0 (in reverse order):
for (int i = children.length - 1; i >= 0; i--) {
createTreeItem(widget, children[i], 0);
}
}
} finally {
Expand All @@ -856,16 +859,16 @@ void createChildren(final Widget widget, boolean materialize) {
}

/**
* Creates a single item for the given parent and synchronizes it with the
* given element.
* Creates a single item for the given parent and synchronizes it with the given
* element. The fastest way to insert many items is documented in
* {@link TreeItem#TreeItem(Tree,int,int)}
*
* @param parent
* the parent widget
* @param element
* the element
* @param index
* if non-negative, indicates the position to insert the item
* into its parent
* @param parent the parent widget
* @param element the element
* @param index if non-negative, indicates the position to insert the item
* into its parent
* @see org.eclipse.swt.widgets.TreeItem#TreeItem(org.eclipse.swt.widgets.Tree,
* int, int)
*/
protected void createTreeItem(Widget parent, Object element, int index) {
Item item = newItem(parent, SWT.NULL, index);
Expand Down Expand Up @@ -1831,6 +1834,7 @@ protected void internalExpandToLevel(Widget widget, int level) {
return;
}
createChildren(widget, false);
// XXX for performance widget should be expanded after expanding children:
if (widget instanceof Item) {
setExpanded((Item) widget, true);
}
Expand All @@ -1844,6 +1848,7 @@ protected void internalExpandToLevel(Widget widget, int level) {
}
}
}
// XXX expanding here fails on linux
}
}

Expand Down
Expand Up @@ -1150,8 +1150,9 @@ void handleExpandableNodeClicked(Widget w) {
item.dispose();

// create children on parent
for (Object element : children) {
createTreeItem(parent, element, -1);
// For performance insert every item at index 0 (in reverse order):
for (int i = children.length - 1; i >= 0; i--) {
createTreeItem(parent, children[i], 0);
}

// reset the selection. client's selection listener should not be triggered.
Expand Down

0 comments on commit 5930a51

Please sign in to comment.