[csharp][unity] Performed some exposed list optimizations by using added method EnsureSize which does not zero excess entries. Closes #2436.

This commit is contained in:
Harald Csaszar 2025-11-17 19:51:10 +01:00
parent c830f12423
commit c4aebc14ab
9 changed files with 52 additions and 45 deletions

View File

@ -274,7 +274,7 @@ namespace Spine {
bool shortestRotation = current.shortestRotation;
bool firstFrame = !shortestRotation && current.timelinesRotation.Count != timelineCount << 1;
if (firstFrame) current.timelinesRotation.Resize(timelineCount << 1);
if (firstFrame) current.timelinesRotation.EnsureSize(timelineCount << 1);
float[] timelinesRotation = current.timelinesRotation.Items;
for (int ii = 0; ii < timelineCount; ii++) {
@ -390,7 +390,7 @@ namespace Spine {
bool shortestRotation = from.shortestRotation;
bool firstFrame = !shortestRotation && from.timelinesRotation.Count != timelineCount << 1;
if (firstFrame) from.timelinesRotation.Resize(timelineCount << 1);
if (firstFrame) from.timelinesRotation.EnsureSize(timelineCount << 1);
float[] timelinesRotation = from.timelinesRotation.Items;
from.totalAlpha = 0;
@ -827,7 +827,7 @@ namespace Spine {
private TrackEntry ExpandToIndex (int index) {
if (index < tracks.Count) return tracks.Items[index];
tracks.Resize(index + 1);
tracks.EnsureSize(index + 1);
return null;
}
@ -898,7 +898,7 @@ namespace Spine {
TrackEntry to = entry.mixingTo;
Timeline[] timelines = entry.animation.timelines.Items;
int timelinesCount = entry.animation.timelines.Count;
int[] timelineMode = entry.timelineMode.Resize(timelinesCount).Items;
int[] timelineMode = entry.timelineMode.EnsureSize(timelinesCount).Items;
entry.timelineHoldMix.Clear();
TrackEntry[] timelineHoldMix = entry.timelineHoldMix.Resize(timelinesCount).Items;
HashSet<string> propertyIds = this.propertyIds;

View File

@ -102,6 +102,15 @@ namespace Spine {
return this;
}
public ExposedList<T> EnsureSize (int newSize) {
int itemsLength = Items.Length;
if (newSize > itemsLength) {
Array.Resize(ref Items, newSize);
}
Count = newSize;
return this;
}
public void EnsureCapacity (int min) {
if (Items.Length < min) {
int newCapacity = Items.Length == 0 ? DefaultCapacity : Items.Length * 2;

View File

@ -83,7 +83,7 @@ namespace Spine {
bool tangents = data.rotateMode == RotateMode.Tangent, scale = data.rotateMode == RotateMode.ChainScale;
int boneCount = this.bones.Count, spacesCount = tangents ? boneCount : boneCount + 1;
BonePose[] bonesItems = this.bones.Items;
float[] spaces = this.spaces.Resize(spacesCount).Items, lengths = scale ? this.lengths.Resize(boneCount).Items : null;
float[] spaces = this.spaces.EnsureSize(spacesCount).Items, lengths = scale ? this.lengths.EnsureSize(boneCount).Items : null;
float spacing = p.spacing;
switch (data.spacingMode) {
case SpacingMode.Percent:
@ -200,7 +200,7 @@ namespace Spine {
float[] ComputeWorldPositions (Skeleton skeleton, PathAttachment path, int spacesCount, bool tangents) {
Slot slot = this.slot;
float position = applied.position;
float[] spaces = this.spaces.Items, output = this.positions.Resize(spacesCount * 3 + 2).Items, world;
float[] spaces = this.spaces.Items, output = this.positions.EnsureSize(spacesCount * 3 + 2).Items, world;
bool closed = path.Closed;
int verticesLength = path.WorldVerticesLength, curveCount = verticesLength / 6, prevCurve = NONE;
@ -224,7 +224,7 @@ namespace Spine {
break;
}
world = this.world.Resize(8).Items;
world = this.world.EnsureSize(8).Items;
for (int i = 0, o = 0, curve = 0; i < spacesCount; i++, o += 3) {
float space = spaces[i] * multiplier;
position += space;
@ -279,7 +279,7 @@ namespace Spine {
// World vertices.
if (closed) {
verticesLength += 2;
world = this.world.Resize(verticesLength).Items;
world = this.world.EnsureSize(verticesLength).Items;
path.ComputeWorldVertices(skeleton, slot, 2, verticesLength - 4, world, 0, 2);
path.ComputeWorldVertices(skeleton, slot, 0, 2, world, verticesLength - 4, 2);
world[verticesLength - 2] = world[0];
@ -287,12 +287,12 @@ namespace Spine {
} else {
curveCount--;
verticesLength -= 4;
world = this.world.Resize(verticesLength).Items;
world = this.world.EnsureSize(verticesLength).Items;
path.ComputeWorldVertices(skeleton, slot, 2, verticesLength, world, 0, 2);
}
// Curve lengths.
float[] curves = this.curves.Resize(curveCount).Items;
float[] curves = this.curves.EnsureSize(curveCount).Items;
pathLength = 0;
float x1 = world[0], y1 = world[1], cx1 = 0, cy1 = 0, cx2 = 0, cy2 = 0, x2 = 0, y2 = 0;
float tmpx, tmpy, dddfx, dddfy, ddfx, ddfy, dfx, dfy;

View File

@ -192,7 +192,7 @@ namespace Spine {
o[i] = input.ReadString();
// Bones.
BoneData[] bones = skeletonData.bones.Resize(n = input.ReadInt(true)).Items;
BoneData[] bones = skeletonData.bones.EnsureSize(n = input.ReadInt(true)).Items;
for (int i = 0; i < n; i++) {
string name = input.ReadString();
BoneData parent = i == 0 ? null : bones[input.ReadInt(true)];
@ -217,7 +217,7 @@ namespace Spine {
}
// Slots.
SlotData[] slots = skeletonData.slots.Resize(n = input.ReadInt(true)).Items;
SlotData[] slots = skeletonData.slots.EnsureSize(n = input.ReadInt(true)).Items;
for (int i = 0; i < n; i++) {
string slotName = input.ReadString();
@ -239,7 +239,7 @@ namespace Spine {
// Constraints.
int constraintCount = input.ReadInt(true);
IConstraintData[] constraints = skeletonData.constraints.Resize(constraintCount).Items;
IConstraintData[] constraints = skeletonData.constraints.EnsureSize(constraintCount).Items;
for (int i = 0; i < constraintCount; i++) {
string name = input.ReadString();
int nn;
@ -247,7 +247,7 @@ namespace Spine {
switch (input.ReadUByte()) {
case CONSTRAINT_IK: {
var data = new IkConstraintData(name);
BoneData[] constraintBones = data.bones.Resize(nn = input.ReadInt(true)).Items;
BoneData[] constraintBones = data.bones.EnsureSize(nn = input.ReadInt(true)).Items;
for (int ii = 0; ii < nn; ii++)
constraintBones[ii] = bones[input.ReadInt(true)];
data.target = bones[input.ReadInt(true)];
@ -265,7 +265,7 @@ namespace Spine {
}
case CONSTRAINT_TRANSFORM: {
var data = new TransformConstraintData(name);
BoneData[] constraintBones = data.bones.Resize(nn = input.ReadInt(true)).Items;
BoneData[] constraintBones = data.bones.EnsureSize(nn = input.ReadInt(true)).Items;
for (int ii = 0; ii < nn; ii++)
constraintBones[ii] = bones[input.ReadInt(true)];
data.source = bones[input.ReadInt(true)];
@ -275,7 +275,7 @@ namespace Spine {
data.localTarget = (flags & 4) != 0;
data.additive = (flags & 8) != 0;
data.clamp = (flags & 16) != 0;
FromProperty[] froms = data.properties.Resize(nn = flags >> 5).Items;
FromProperty[] froms = data.properties.EnsureSize(nn = flags >> 5).Items;
for (int ii = 0, tn; ii < nn; ii++) {
float fromScale = 1;
FromProperty from;
@ -297,7 +297,7 @@ namespace Spine {
default: from = null; break;
}
from.offset = input.ReadFloat() * fromScale;
ToProperty[] tos = from.to.Resize(tn = input.ReadSByte()).Items;
ToProperty[] tos = from.to.EnsureSize(tn = input.ReadSByte()).Items;
for (int t = 0; t < tn; t++) {
float toScale = 1;
ToProperty to;
@ -345,7 +345,7 @@ namespace Spine {
}
case CONSTRAINT_PATH: {
var data = new PathConstraintData(name);
BoneData[] constraintBones = data.bones.Resize(nn = input.ReadInt(true)).Items;
BoneData[] constraintBones = data.bones.EnsureSize(nn = input.ReadInt(true)).Items;
for (int ii = 0; ii < nn; ii++)
constraintBones[ii] = bones[input.ReadInt(true)];
data.slot = slots[input.ReadInt(true)];
@ -447,7 +447,7 @@ namespace Spine {
// Skins.
{
int i = skeletonData.skins.Count;
o = skeletonData.skins.Resize(n = i + input.ReadInt(true)).Items;
o = skeletonData.skins.EnsureSize(n = i + input.ReadInt(true)).Items;
for (; i < n; i++)
o[i] = ReadSkin(input, skeletonData, false, nonessential);
}
@ -466,7 +466,7 @@ namespace Spine {
linkedMeshes.Clear();
// Events.
o = skeletonData.events.Resize(n = input.ReadInt(true)).Items;
o = skeletonData.events.EnsureSize(n = input.ReadInt(true)).Items;
for (int i = 0; i < n; i++) {
var data = new EventData(input.ReadString());
data.Int = input.ReadInt(false);
@ -481,7 +481,7 @@ namespace Spine {
}
// Animations.
Animation[] animations = skeletonData.animations.Resize(n = input.ReadInt(true)).Items;
Animation[] animations = skeletonData.animations.EnsureSize(n = input.ReadInt(true)).Items;
for (int i = 0; i < n; i++)
animations[i] = ReadAnimation(input, input.ReadString(), skeletonData);
@ -513,12 +513,12 @@ namespace Spine {
if (nonessential) input.ReadInt(); // discard, Color.rgba8888ToColor(skin.color, input.readInt());
int n;
object[] from = skeletonData.bones.Items, to = skin.bones.Resize(n = input.ReadInt(true)).Items;
object[] from = skeletonData.bones.Items, to = skin.bones.EnsureSize(n = input.ReadInt(true)).Items;
for (int i = 0; i < n; i++)
to[i] = from[input.ReadInt(true)];
from = skeletonData.constraints.Items;
to = skin.constraints.Resize(n = input.ReadInt(true)).Items;
to = skin.constraints.EnsureSize(n = input.ReadInt(true)).Items;
for (int i = 0; i < n; i++)
to[i] = from[input.ReadInt(true)];

View File

@ -53,7 +53,7 @@ namespace Spine {
clipAttachment = clip;
int n = clip.worldVerticesLength;
float[] vertices = clippingPolygon.Resize(n).Items;
float[] vertices = clippingPolygon.EnsureSize(n).Items;
clip.ComputeWorldVertices(skeleton, slot, 0, n, vertices, 0, 2);
MakeClockwise(clippingPolygon);
clippingPolygons = triangulator.Decompose(clippingPolygon, triangulator.Triangulate(clippingPolygon));
@ -106,7 +106,7 @@ namespace Spine {
if (clipOutputLength == 0) continue;
int clipOutputCount = clipOutputLength >> 1;
float[] clippedVerticesItems = clippedVertices.Resize(s + clipOutputCount * 2).Items;
float[] clippedVerticesItems = clippedVertices.EnsureSize(s + clipOutputCount * 2).Items;
for (int ii = 0; ii < clipOutputLength; ii += 2, s += 2) {
float x = clipOutputItems[ii], y = clipOutputItems[ii + 1];
clippedVerticesItems[s] = x;
@ -114,7 +114,7 @@ namespace Spine {
}
s = clippedTriangles.Count;
int[] clippedTrianglesItems = clippedTriangles.Resize(s + 3 * (clipOutputCount - 2)).Items;
int[] clippedTrianglesItems = clippedTriangles.EnsureSize(s + 3 * (clipOutputCount - 2)).Items;
clipOutputCount--;
for (int ii = 1; ii < clipOutputCount; ii++, s += 3) {
clippedTrianglesItems[s] = index;
@ -123,7 +123,7 @@ namespace Spine {
}
index += clipOutputCount + 1;
} else {
float[] clippedVerticesItems = clippedVertices.Resize(s + 3 * 2).Items;
float[] clippedVerticesItems = clippedVertices.EnsureSize(s + 3 * 2).Items;
clippedVerticesItems[s] = x1;
clippedVerticesItems[s + 1] = y1;
clippedVerticesItems[s + 2] = x2;
@ -132,7 +132,7 @@ namespace Spine {
clippedVerticesItems[s + 5] = y3;
s = clippedTriangles.Count;
int[] clippedTrianglesItems = clippedTriangles.Resize(s + 3).Items;
int[] clippedTrianglesItems = clippedTriangles.EnsureSize(s + 3).Items;
clippedTrianglesItems[s] = index;
clippedTrianglesItems[s + 1] = index + 1;
clippedTrianglesItems[s + 2] = index + 2;
@ -178,8 +178,8 @@ namespace Spine {
float d = 1 / (d0 * d2 + d1 * (y1 - y3));
int clipOutputCount = clipOutputLength >> 1;
float[] clippedVerticesItems = clippedVertices.Resize(s + clipOutputCount * 2).Items;
float[] clippedUVsItems = clippedUVs.Resize(s + clipOutputCount * 2).Items;
float[] clippedVerticesItems = clippedVertices.EnsureSize(s + clipOutputCount * 2).Items;
float[] clippedUVsItems = clippedUVs.EnsureSize(s + clipOutputCount * 2).Items;
for (int ii = 0; ii < clipOutputLength; ii += 2, s += 2) {
float x = clipOutputItems[ii], y = clipOutputItems[ii + 1];
clippedVerticesItems[s] = x;
@ -193,7 +193,7 @@ namespace Spine {
}
s = clippedTriangles.Count;
int[] clippedTrianglesItems = clippedTriangles.Resize(s + 3 * (clipOutputCount - 2)).Items;
int[] clippedTrianglesItems = clippedTriangles.EnsureSize(s + 3 * (clipOutputCount - 2)).Items;
clipOutputCount--;
for (int ii = 1; ii < clipOutputCount; ii++, s += 3) {
clippedTrianglesItems[s] = index;
@ -202,8 +202,8 @@ namespace Spine {
}
index += clipOutputCount + 1;
} else {
float[] clippedVerticesItems = clippedVertices.Resize(s + 3 * 2).Items;
float[] clippedUVsItems = clippedUVs.Resize(s + 3 * 2).Items;
float[] clippedVerticesItems = clippedVertices.EnsureSize(s + 3 * 2).Items;
float[] clippedUVsItems = clippedUVs.EnsureSize(s + 3 * 2).Items;
clippedVerticesItems[s] = x1;
clippedVerticesItems[s + 1] = y1;
clippedVerticesItems[s + 2] = x2;
@ -219,7 +219,7 @@ namespace Spine {
clippedUVsItems[s + 5] = v3;
s = clippedTriangles.Count;
int[] clippedTrianglesItems = clippedTriangles.Resize(s + 3).Items;
int[] clippedTrianglesItems = clippedTriangles.EnsureSize(s + 3).Items;
clippedTrianglesItems[s] = index;
clippedTrianglesItems[s + 1] = index + 1;
clippedTrianglesItems[s + 2] = index + 2;
@ -324,7 +324,7 @@ namespace Spine {
for (int i = 0, n = output.Count - 2; i < n; i++)
originalOutput.Add(output.Items[i]);
} else
originalOutput.Resize(originalOutput.Count - 2);
originalOutput.EnsureSize(originalOutput.Count - 2);
return clipped;
}

View File

@ -47,12 +47,12 @@ namespace Spine {
ExposedList<int> indicesArray = this.indicesArray;
indicesArray.Clear();
int[] indices = indicesArray.Resize(vertexCount).Items;
int[] indices = indicesArray.EnsureSize(vertexCount).Items;
for (int i = 0; i < vertexCount; i++)
indices[i] = i;
ExposedList<bool> isConcaveArray = this.isConcaveArray;
bool[] isConcave = isConcaveArray.Resize(vertexCount).Items;
bool[] isConcave = isConcaveArray.EnsureSize(vertexCount).Items;
for (int i = 0, n = vertexCount; i < n; ++i)
isConcave[i] = IsConcave(i, vertexCount, vertices, indices);

View File

@ -2,7 +2,7 @@
"name": "com.esotericsoftware.spine.spine-csharp",
"displayName": "spine-csharp Runtime",
"description": "This plugin provides the spine-csharp core runtime.",
"version": "4.3.10",
"version": "4.3.11",
"unity": "2018.3",
"author": {
"name": "Esoteric Software",

View File

@ -558,9 +558,7 @@ namespace Spine.Unity {
Settings settings = this.settings;
int newSubmeshCount = submeshIndex + 1;
if (submeshes.Items.Length < newSubmeshCount)
submeshes.Resize(newSubmeshCount);
submeshes.Count = newSubmeshCount;
submeshes.EnsureSize(newSubmeshCount);
ExposedList<int> submesh = submeshes.Items[submeshIndex];
if (submesh == null)
submeshes.Items[submeshIndex] = submesh = new ExposedList<int>();
@ -1078,7 +1076,7 @@ namespace Spine.Unity {
if (updateTriangles) {
// Match submesh buffers count with submeshInstruction count.
if (this.submeshes.Items.Length < submeshInstructionCount) {
this.submeshes.Resize(submeshInstructionCount);
this.submeshes.EnsureSize(submeshInstructionCount);
for (int i = 0, n = submeshInstructionCount; i < n; i++) {
ExposedList<int> submeshBuffer = this.submeshes.Items[i];
if (submeshBuffer == null)
@ -1329,8 +1327,8 @@ namespace Spine.Unity {
uv2 = new ExposedList<Vector2>(minimumVertexCount);
uv3 = new ExposedList<Vector2>(minimumVertexCount);
}
uv2.Resize(minimumVertexCount);
uv3.Resize(minimumVertexCount);
uv2.EnsureSize(minimumVertexCount);
uv3.EnsureSize(minimumVertexCount);
}
if (includeNormals) {

View File

@ -2,7 +2,7 @@
"name": "com.esotericsoftware.spine.spine-unity",
"displayName": "spine-unity Runtime",
"description": "This plugin provides the spine-unity runtime core and examples. Spine Examples can be installed via the Samples tab.",
"version": "4.3.28",
"version": "4.3.29",
"unity": "2018.3",
"author": {
"name": "Esoteric Software",