From 42da98a3dd167b7deb5d3cd5db765539ccec4cd1 Mon Sep 17 00:00:00 2001 From: Musa Asukhanov Date: Tue, 28 Oct 2025 13:05:58 +0300 Subject: [PATCH] [ts] Replace Array constructors with dynamic initialization (#2955) * [ts] Replace Array constructors with dynamic initialization --------- Co-authored-by: Davide Tantillo --- spine-ts/spine-core/src/SkeletonBinary.ts | 4 ++-- spine-ts/spine-core/src/Utils.ts | 6 +++--- spine-ts/spine-core/src/attachments/Attachment.ts | 2 +- spine-ts/spine-core/src/attachments/MeshAttachment.ts | 8 ++++---- spine-ts/spine-core/src/attachments/PathAttachment.ts | 2 +- spine-ts/spine-player/src/Player.ts | 2 +- .../spine-webcomponents/src/SpineWebComponentSkeleton.ts | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/spine-ts/spine-core/src/SkeletonBinary.ts b/spine-ts/spine-core/src/SkeletonBinary.ts index 04c6c59f0..e6acb169f 100644 --- a/spine-ts/spine-core/src/SkeletonBinary.ts +++ b/spine-ts/spine-core/src/SkeletonBinary.ts @@ -648,7 +648,7 @@ export class SkeletonBinary { } private readFloatArray (input: BinaryInput, n: number, scale: number): number[] { - const array = new Array(n); + const array: number[] = []; if (scale === 1) { for (let i = 0; i < n; i++) array[i] = input.readFloat(); @@ -660,7 +660,7 @@ export class SkeletonBinary { } private readShortArray (input: BinaryInput, n: number): number[] { - const array = new Array(n); + const array: number[] = []; for (let i = 0; i < n; i++) array[i] = input.readInt(true); return array; diff --git a/spine-ts/spine-core/src/Utils.ts b/spine-ts/spine-core/src/Utils.ts index 6079fef00..7a6a00aa3 100644 --- a/spine-ts/spine-core/src/Utils.ts +++ b/spine-ts/spine-core/src/Utils.ts @@ -301,7 +301,7 @@ export class Utils { } static newArray (size: number, defaultValue: T): Array { - const array = new Array(size); + const array: T[] = []; for (let i = 0; i < size; i++) array[i] = defaultValue; return array; } @@ -310,7 +310,7 @@ export class Utils { if (Utils.SUPPORTS_TYPED_ARRAYS) return new Float32Array(size) else { - const array = new Array(size); + const array: number[] = []; for (let i = 0; i < array.length; i++) array[i] = 0; return array; } @@ -320,7 +320,7 @@ export class Utils { if (Utils.SUPPORTS_TYPED_ARRAYS) return new Int16Array(size) else { - const array = new Array(size); + const array: number[] = []; for (let i = 0; i < array.length; i++) array[i] = 0; return array; } diff --git a/spine-ts/spine-core/src/attachments/Attachment.ts b/spine-ts/spine-core/src/attachments/Attachment.ts index 4a5de7a50..1669fffc6 100644 --- a/spine-ts/spine-core/src/attachments/Attachment.ts +++ b/spine-ts/spine-core/src/attachments/Attachment.ts @@ -146,7 +146,7 @@ export abstract class VertexAttachment extends Attachment { /** Does not copy id (generated) or name (set on construction). **/ copyTo (attachment: VertexAttachment) { if (this.bones) { - attachment.bones = new Array(this.bones.length); + attachment.bones = []; Utils.arrayCopy(this.bones, 0, attachment.bones, 0, this.bones.length); } else attachment.bones = null; diff --git a/spine-ts/spine-core/src/attachments/MeshAttachment.ts b/spine-ts/spine-core/src/attachments/MeshAttachment.ts index d0adfa27b..731e2bc49 100644 --- a/spine-ts/spine-core/src/attachments/MeshAttachment.ts +++ b/spine-ts/spine-core/src/attachments/MeshAttachment.ts @@ -176,11 +176,11 @@ export class MeshAttachment extends VertexAttachment implements HasTextureRegion copy.color.setFromColor(this.color); this.copyTo(copy); - copy.regionUVs = new Array(this.regionUVs.length); + copy.regionUVs = []; Utils.arrayCopy(this.regionUVs, 0, copy.regionUVs, 0, this.regionUVs.length); - copy.uvs = this.uvs instanceof Float32Array ? Utils.newFloatArray(this.uvs.length) : new Array(this.uvs.length); + copy.uvs = this.uvs instanceof Float32Array ? Utils.newFloatArray(this.uvs.length) : []; Utils.arrayCopy(this.uvs, 0, copy.uvs, 0, this.uvs.length); - copy.triangles = new Array(this.triangles.length); + copy.triangles = []; Utils.arrayCopy(this.triangles, 0, copy.triangles, 0, this.triangles.length); copy.hullLength = this.hullLength; @@ -188,7 +188,7 @@ export class MeshAttachment extends VertexAttachment implements HasTextureRegion // Nonessential. if (this.edges) { - copy.edges = new Array(this.edges.length); + copy.edges = []; Utils.arrayCopy(this.edges, 0, copy.edges, 0, this.edges.length); } copy.width = this.width; diff --git a/spine-ts/spine-core/src/attachments/PathAttachment.ts b/spine-ts/spine-core/src/attachments/PathAttachment.ts index b02218729..5d5e1a8ae 100644 --- a/spine-ts/spine-core/src/attachments/PathAttachment.ts +++ b/spine-ts/spine-core/src/attachments/PathAttachment.ts @@ -56,7 +56,7 @@ export class PathAttachment extends VertexAttachment { copy (): Attachment { const copy = new PathAttachment(this.name); this.copyTo(copy); - copy.lengths = new Array(this.lengths.length); + copy.lengths = []; Utils.arrayCopy(this.lengths, 0, copy.lengths, 0, this.lengths.length); copy.closed = closed; copy.constantSpeed = this.constantSpeed; diff --git a/spine-ts/spine-player/src/Player.ts b/spine-ts/spine-player/src/Player.ts index 4ae81c439..1b0e4d9df 100644 --- a/spine-ts/spine-player/src/Player.ts +++ b/spine-ts/spine-player/src/Player.ts @@ -803,7 +803,7 @@ export class SpinePlayer implements Disposable { let minX = 100000000, maxX = -100000000, minY = 100000000, maxY = -100000000; const offset = new Vector2(), size = new Vector2(); - const tempArray = new Array(2); + const tempArray = [0, 0]; for (let i = 0; i < steps; i++, time += stepTime) { animation.apply(this.skeleton!, time, time, false, [], 1, MixBlend.setup, MixDirection.in, false); this.skeleton!.updateWorldTransform(Physics.update); diff --git a/spine-ts/spine-webcomponents/src/SpineWebComponentSkeleton.ts b/spine-ts/spine-webcomponents/src/SpineWebComponentSkeleton.ts index f3f802eab..d4793a595 100644 --- a/spine-ts/spine-webcomponents/src/SpineWebComponentSkeleton.ts +++ b/spine-ts/spine-webcomponents/src/SpineWebComponentSkeleton.ts @@ -1276,7 +1276,7 @@ export class SpineWebComponentSkeleton extends HTMLElement implements Disposable skeleton.setupPose(); const offset = new Vector2(), size = new Vector2(); - const tempArray = new Array(2); + const tempArray = [0, 0]; if (!animation) { skeleton.updateWorldTransform(Physics.update); skeleton.getBounds(offset, size, tempArray, renderer.skeletonRenderer.getSkeletonClipping());