From 5c454b1bb7796b1ac1dee01ed8d0ebb3b1f813b5 Mon Sep 17 00:00:00 2001 From: koteelok Date: Sun, 19 Oct 2025 23:36:27 +0300 Subject: [PATCH] [ts] Replace Array constructors with dynamic initialization for packed number arrays --- spine-ts/spine-core/src/SkeletonBinary.ts | 4 ++-- spine-ts/spine-core/src/Utils.ts | 10 +++++----- 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 +- .../src/SpineWebComponentSkeleton.ts | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/spine-ts/spine-core/src/SkeletonBinary.ts b/spine-ts/spine-core/src/SkeletonBinary.ts index 1e4228a5cd..612dfe54ac 100644 --- a/spine-ts/spine-core/src/SkeletonBinary.ts +++ b/spine-ts/spine-core/src/SkeletonBinary.ts @@ -652,7 +652,7 @@ export class SkeletonBinary { } private readFloatArray (input: BinaryInput, n: number, scale: number): number[] { - let array = new Array(n); + let array = []; if (scale == 1) { for (let i = 0; i < n; i++) array[i] = input.readFloat(); @@ -664,7 +664,7 @@ export class SkeletonBinary { } private readShortArray (input: BinaryInput, n: number): number[] { - let array = new Array(n); + let array = []; 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 e9255fc594..afdf695c0e 100644 --- a/spine-ts/spine-core/src/Utils.ts +++ b/spine-ts/spine-core/src/Utils.ts @@ -296,7 +296,7 @@ export class Utils { } static newArray (size: number, defaultValue: T): Array { - let array = new Array(size); + let array = new Array(); for (let i = 0; i < size; i++) array[i] = defaultValue; return array; } @@ -305,8 +305,8 @@ export class Utils { if (Utils.SUPPORTS_TYPED_ARRAYS) return new Float32Array(size) else { - let array = new Array(size); - for (let i = 0; i < array.length; i++) array[i] = 0; + let array = new Array(); + for (let i = 0; i < size; i++) array[i] = 0; return array; } } @@ -315,8 +315,8 @@ export class Utils { if (Utils.SUPPORTS_TYPED_ARRAYS) return new Int16Array(size) else { - let array = new Array(size); - for (let i = 0; i < array.length; i++) array[i] = 0; + let array = new Array(); + for (let i = 0; i < size; 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 f884dc4dd5..45ecc3afc2 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 be75a1c89a..7e23d1c4d7 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 330fcd6abd..3f52ef3b46 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 { let 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 8de243c471..fc85359de2 100644 --- a/spine-ts/spine-player/src/Player.ts +++ b/spine-ts/spine-player/src/Player.ts @@ -811,7 +811,7 @@ export class SpinePlayer implements Disposable { let minX = 100000000, maxX = -100000000, minY = 100000000, maxY = -100000000; let 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 42e898038f..3a59833222 100644 --- a/spine-ts/spine-webcomponents/src/SpineWebComponentSkeleton.ts +++ b/spine-ts/spine-webcomponents/src/SpineWebComponentSkeleton.ts @@ -1274,7 +1274,7 @@ export class SpineWebComponentSkeleton extends HTMLElement implements Disposable skeleton.setupPose(); let 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());