From b4f363ba0b708e154090992f019ef850b970b72e Mon Sep 17 00:00:00 2001 From: Mat Groves Date: Wed, 1 May 2024 20:16:15 +0100 Subject: [PATCH] optimise destroy remove children --- src/scene/container/Container.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/scene/container/Container.ts b/src/scene/container/Container.ts index 58393e099b..5a84c43d20 100644 --- a/src/scene/container/Container.ts +++ b/src/scene/container/Container.ts @@ -1328,6 +1328,9 @@ export class Container extends EventE if (this.destroyed) return; this.destroyed = true; + // remove children is faster than removeChild.. + const oldChildren = this.removeChildren(0, this.children.length); + this.removeFromParent(); this.parent = null; this._mask = null; @@ -1344,8 +1347,6 @@ export class Container extends EventE const destroyChildren = typeof options === 'boolean' ? options : options?.children; - const oldChildren = this.removeChildren(0, this.children.length); - if (destroyChildren) { for (let i = 0; i < oldChildren.length; ++i)