Skip to content

Commit

Permalink
[prefab] Properly pre allocate children array
Browse files Browse the repository at this point in the history
  • Loading branch information
EspeuteClement committed Mar 27, 2024
1 parent a4937f6 commit 5f3a57f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 6 additions & 1 deletion hrt/prefab/Macros.hx
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,12 @@ class Macros {
else
{
var _a : Array<Dynamic> = cast $e{source};
[for (_elem in _a) $e{hrt.prefab.Macros.deepCopyRec(params[0], macro @:pos(source.pos) _elem, targetType, null, custom, true)}];
var target = [];
target.resize(_a.length);
for (idx => _elem in _a) {
target[idx] = $e{hrt.prefab.Macros.deepCopyRec(params[0], macro @:pos(source.pos) _elem, targetType, null, custom, true)};
}
target;
}
};
case "String":
Expand Down
10 changes: 8 additions & 2 deletions hrt/prefab/Prefab.hx
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,14 @@ class Prefab {

inst.copy(this);
if (withChildren) {
for (child in children) {
child.clone(inst, sh);
inst.children.resize(children.length);
for (idx => child in children) {
var cloneChild = child.clone(null, sh);

// "parent" setter pushes into children, but we don't want that
// as we have prealocated the array children
@:bypassAccessor cloneChild.parent = inst;
inst.children[idx] = cloneChild;
}
}

Expand Down

0 comments on commit 5f3a57f

Please sign in to comment.