Skip to content

Commit a00ebef

Browse files
authored
Merge pull request #98 from gadget-inc/array-push-multi
Improve QuickArray creation performance
2 parents 88406c8 + 98f7005 commit a00ebef

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

src/array.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ export class ArrayType<T extends IAnyType> extends BaseType<Array<T["InputType"]
8282
instantiate(snapshot: this["InputType"] | undefined, context: TreeContext, parent: IStateTreeNode | null): this["InstanceType"] {
8383
const array = new QuickArray<T>(this, parent, context);
8484
if (snapshot) {
85-
for (let index = 0; index < snapshot?.length; ++index) {
86-
array.push(this.childrenType.instantiate(snapshot[index], context, array));
87-
}
85+
array.push(...snapshot.map((element) => this.childrenType.instantiate(element, context, array)));
8886
}
8987
return array as this["InstanceType"];
9088
}

0 commit comments

Comments
 (0)