Skip to content

Commit

Permalink
optimize performance on many of elements add to a container
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalgust committed Jun 30, 2024
1 parent a936a98 commit bcd305c
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions extlib/xgui/src/main/java/org/mini/gui/GContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,18 @@ void addImpl(int index, GObject nko) {
if (nko != null) {
synchronized (elements) {
if (!elements.contains(nko)) {
//根据layer 排序,加入到elements容器中
if (index < 0) {
index = 0;
} else if (index > elements.size()) {
index = elements.size();
}
for (int i = 0; i < elements.size(); i++){
if (elements.get(i).getLayer() > nko.getLayer()) {
index = i;
break;
}
}
elements.add(index, nko);
nko.setParent(this);
nko.init();
Expand Down Expand Up @@ -361,7 +373,7 @@ public void removeChildrenListener(GChildrenListener listener) {
}

public void onAdd(GObject obj) {
reLayer();
//reLayer();
for (GChildrenListener l : childrenListeners) {
try {
l.onChildAdd(obj);
Expand All @@ -372,7 +384,7 @@ public void onAdd(GObject obj) {
}

public void onRemove(GObject obj) {
reLayer();
//reLayer();
for (GChildrenListener l : childrenListeners) {
try {
l.onChildRemove(obj);
Expand Down

0 comments on commit bcd305c

Please sign in to comment.