When removing a child, set key "parent" to null, don't delete it

Structural changes to objects are relatively more expensive and
harder to optimize for modern JavaScript compilers, compared to
just changing object's key values. The parent property of nodes
is already set to null now, as part constructing the object.
Setting it back to null on removal / destroy of objects is more
consistent and a tiny little bit more efficient.
This commit is contained in:
VladimirTechMan 2019-02-03 22:47:50 +03:00
parent 6b1cf1d306
commit 15e7477e81
2 changed files with 3 additions and 3 deletions

View File

@ -66,7 +66,7 @@ export abstract class Container extends Node {
for (var i = 0; i < children.length; i++) {
child = children[i];
// reset parent to prevent many _setChildrenIndices calls
delete child.parent;
child.parent = null;
child.index = 0;
child.remove();
}
@ -85,7 +85,7 @@ export abstract class Container extends Node {
for (var i = 0; i < children.length; i++) {
child = children[i];
// reset parent to prevent many _setChildrenIndices calls
delete child.parent;
child.parent = null;
child.index = 0;
child.destroy();
}

View File

@ -719,7 +719,7 @@ export abstract class Node {
if (parent && parent.children) {
parent.children.splice(this.index, 1);
parent._setChildrenIndices();
delete this.parent;
this.parent = null;
}
// every cached attr that is calculated via node tree