[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[] {
const array = new Array<number>(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<number>(n);
const array: number[] = [];
for (let i = 0; i < n; i++)
array[i] = input.readInt(true);
return array;

View File

@ -301,7 +301,7 @@ export class Utils {
}
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;
return array;
}
@ -310,7 +310,7 @@ export class Utils {
if (Utils.SUPPORTS_TYPED_ARRAYS)
return new Float32Array(size)
else {
const array = new Array<number>(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<number>(size);
const array: number[] = [];
for (let i = 0; i < array.length; i++) array[i] = 0;
return array;
}

View File

@ -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<number>(this.bones.length);
attachment.bones = [];
Utils.arrayCopy(this.bones, 0, attachment.bones, 0, this.bones.length);
} else
attachment.bones = null;

View File

@ -176,11 +176,11 @@ export class MeshAttachment extends VertexAttachment implements HasTextureRegion
copy.color.setFromColor(this.color);
this.copyTo(copy);
copy.regionUVs = new Array<number>(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<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);
copy.triangles = new Array<number>(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<number>(this.edges.length);
copy.edges = [];
Utils.arrayCopy(this.edges, 0, copy.edges, 0, this.edges.length);
}
copy.width = this.width;

View File

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

View File

@ -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<number>(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);

View File

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