perf: container sorting
This commit is contained in:
parent
866407e31d
commit
c5dbadb66e
|
@ -240,9 +240,22 @@ export default class Container extends Renderable {
|
|||
child.sort();
|
||||
}
|
||||
}
|
||||
this.$$children.sort((l, r) => l.$$zIndex - r.$$zIndex);
|
||||
if (!this.container.isFake) {
|
||||
this.container.children = this.$$children.map((child) => child.internal);
|
||||
// Double insertion sort, because mostly-sorted is the usual case.
|
||||
for (let i = 1; i < this.$$children.length; i++) {
|
||||
const current = this.$$children[i];
|
||||
const currentChild = this.container.isFake ? undefined : this.container.children[i];
|
||||
let j = i - 1;
|
||||
while ((j > -1) && (current.$$zIndex < this.$$children[j].$$zIndex)) {
|
||||
this.$$children[j + 1] = this.$$children[j];
|
||||
if (!this.container.isFake) {
|
||||
this.container.swapChildren(this.container.children[j], this.container.children[j + 1]);
|
||||
}
|
||||
j--;
|
||||
}
|
||||
this.$$children[j + 1] = current;
|
||||
if (!this.container.isFake) {
|
||||
this.container.swapChildren(currentChild, this.container.children[j + 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user