[ts] Replace Array constructors with dynamic initialization (#2955)

* [ts] Replace Array constructors with dynamic initialization

---------

Co-authored-by: Davide Tantillo <iamdjj@gmail.com>
This commit is contained in:
Musa Asukhanov 2025-10-28 13:05:58 +03:00 committed by GitHub
parent eb4fb09765
commit 42da98a3dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 13 additions and 13 deletions

View File

@ -648,7 +648,7 @@ export class SkeletonBinary {
} }
private readFloatArray (input: BinaryInput, n: number, scale: number): number[] { private readFloatArray (input: BinaryInput, n: number, scale: number): number[] {
const array = new Array<number>(n); const array: number[] = [];
if (scale === 1) { if (scale === 1) {
for (let i = 0; i < n; i++) for (let i = 0; i < n; i++)
array[i] = input.readFloat(); array[i] = input.readFloat();
@ -660,7 +660,7 @@ export class SkeletonBinary {
} }
private readShortArray (input: BinaryInput, n: number): number[] { private readShortArray (input: BinaryInput, n: number): number[] {
const array = new Array<number>(n); const array: number[] = [];
for (let i = 0; i < n; i++) for (let i = 0; i < n; i++)
array[i] = input.readInt(true); array[i] = input.readInt(true);
return array; return array;

View File

@ -301,7 +301,7 @@ export class Utils {
} }
static newArray<T> (size: number, defaultValue: T): Array<T> { static newArray<T> (size: number, defaultValue: T): Array<T> {
const array = new Array<T>(size); const array: T[] = [];
for (let i = 0; i < size; i++) array[i] = defaultValue; for (let i = 0; i < size; i++) array[i] = defaultValue;
return array; return array;
} }
@ -310,7 +310,7 @@ export class Utils {
if (Utils.SUPPORTS_TYPED_ARRAYS) if (Utils.SUPPORTS_TYPED_ARRAYS)
return new Float32Array(size) return new Float32Array(size)
else { else {
const array = new Array<number>(size); const array: number[] = [];
for (let i = 0; i < array.length; i++) array[i] = 0; for (let i = 0; i < array.length; i++) array[i] = 0;
return array; return array;
} }
@ -320,7 +320,7 @@ export class Utils {
if (Utils.SUPPORTS_TYPED_ARRAYS) if (Utils.SUPPORTS_TYPED_ARRAYS)
return new Int16Array(size) return new Int16Array(size)
else { else {
const array = new Array<number>(size); const array: number[] = [];
for (let i = 0; i < array.length; i++) array[i] = 0; for (let i = 0; i < array.length; i++) array[i] = 0;
return array; return array;
} }

View File

@ -146,7 +146,7 @@ export abstract class VertexAttachment extends Attachment {
/** Does not copy id (generated) or name (set on construction). **/ /** Does not copy id (generated) or name (set on construction). **/
copyTo (attachment: VertexAttachment) { copyTo (attachment: VertexAttachment) {
if (this.bones) { if (this.bones) {
attachment.bones = new Array<number>(this.bones.length); attachment.bones = [];
Utils.arrayCopy(this.bones, 0, attachment.bones, 0, this.bones.length); Utils.arrayCopy(this.bones, 0, attachment.bones, 0, this.bones.length);
} else } else
attachment.bones = null; attachment.bones = null;

View File

@ -176,11 +176,11 @@ export class MeshAttachment extends VertexAttachment implements HasTextureRegion
copy.color.setFromColor(this.color); copy.color.setFromColor(this.color);
this.copyTo(copy); this.copyTo(copy);
copy.regionUVs = new Array<number>(this.regionUVs.length); copy.regionUVs = [];
Utils.arrayCopy(this.regionUVs, 0, copy.regionUVs, 0, this.regionUVs.length); Utils.arrayCopy(this.regionUVs, 0, copy.regionUVs, 0, this.regionUVs.length);
copy.uvs = this.uvs instanceof Float32Array ? Utils.newFloatArray(this.uvs.length) : new Array<number>(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); Utils.arrayCopy(this.uvs, 0, copy.uvs, 0, this.uvs.length);
copy.triangles = new Array<number>(this.triangles.length); copy.triangles = [];
Utils.arrayCopy(this.triangles, 0, copy.triangles, 0, this.triangles.length); Utils.arrayCopy(this.triangles, 0, copy.triangles, 0, this.triangles.length);
copy.hullLength = this.hullLength; copy.hullLength = this.hullLength;
@ -188,7 +188,7 @@ export class MeshAttachment extends VertexAttachment implements HasTextureRegion
// Nonessential. // Nonessential.
if (this.edges) { if (this.edges) {
copy.edges = new Array<number>(this.edges.length); copy.edges = [];
Utils.arrayCopy(this.edges, 0, copy.edges, 0, this.edges.length); Utils.arrayCopy(this.edges, 0, copy.edges, 0, this.edges.length);
} }
copy.width = this.width; copy.width = this.width;

View File

@ -56,7 +56,7 @@ export class PathAttachment extends VertexAttachment {
copy (): Attachment { copy (): Attachment {
const copy = new PathAttachment(this.name); const copy = new PathAttachment(this.name);
this.copyTo(copy); this.copyTo(copy);
copy.lengths = new Array<number>(this.lengths.length); copy.lengths = [];
Utils.arrayCopy(this.lengths, 0, copy.lengths, 0, this.lengths.length); Utils.arrayCopy(this.lengths, 0, copy.lengths, 0, this.lengths.length);
copy.closed = closed; copy.closed = closed;
copy.constantSpeed = this.constantSpeed; copy.constantSpeed = this.constantSpeed;

View File

@ -803,7 +803,7 @@ export class SpinePlayer implements Disposable {
let minX = 100000000, maxX = -100000000, minY = 100000000, maxY = -100000000; let minX = 100000000, maxX = -100000000, minY = 100000000, maxY = -100000000;
const offset = new Vector2(), size = new Vector2(); const offset = new Vector2(), size = new Vector2();
const tempArray = new Array<number>(2); const tempArray = [0, 0];
for (let i = 0; i < steps; i++, time += stepTime) { for (let i = 0; i < steps; i++, time += stepTime) {
animation.apply(this.skeleton!, time, time, false, [], 1, MixBlend.setup, MixDirection.in, false); animation.apply(this.skeleton!, time, time, false, [], 1, MixBlend.setup, MixDirection.in, false);
this.skeleton!.updateWorldTransform(Physics.update); this.skeleton!.updateWorldTransform(Physics.update);

View File

@ -1276,7 +1276,7 @@ export class SpineWebComponentSkeleton extends HTMLElement implements Disposable
skeleton.setupPose(); skeleton.setupPose();
const offset = new Vector2(), size = new Vector2(); const offset = new Vector2(), size = new Vector2();
const tempArray = new Array<number>(2); const tempArray = [0, 0];
if (!animation) { if (!animation) {
skeleton.updateWorldTransform(Physics.update); skeleton.updateWorldTransform(Physics.update);
skeleton.getBounds(offset, size, tempArray, renderer.skeletonRenderer.getSkeletonClipping()); skeleton.getBounds(offset, size, tempArray, renderer.skeletonRenderer.getSkeletonClipping());