diff --git a/FinModelUtility/Formats/Hsd/Hsd/src/schema/animation/DatKeyframesUtil.cs b/FinModelUtility/Formats/Hsd/Hsd/src/schema/animation/DatKeyframesUtil.cs index ea5432f85..44af14757 100644 --- a/FinModelUtility/Formats/Hsd/Hsd/src/schema/animation/DatKeyframesUtil.cs +++ b/FinModelUtility/Formats/Hsd/Hsd/src/schema/animation/DatKeyframesUtil.cs @@ -31,15 +31,17 @@ public static void ReadKeyframes( keyframes.Clear(); var keys = ReadFObjKeys_(br, datKeyframes); - var interpolations = GetInterpolationsFromFObjKeys_(keys); + Span buffer + = stackalloc InterpolationRegisters[keys.Count]; + var interpolations = GetInterpolationsFromFObjKeys_(keys, buffer); - if (interpolations.Count == 0) { + if (interpolations.Length == 0) { return; } DatKeyframe? currentKeyframe = null; - var firstInterpolation = interpolations.First.Value; + var firstInterpolation = interpolations[0]; DatKeyframe nextKeyframe = new() { Frame = firstInterpolation.FromFrame, IncomingValue = firstInterpolation.FromValue, @@ -80,7 +82,7 @@ public static void ReadKeyframes( } } - private class InterpolationRegisters { + private readonly struct InterpolationRegisters { public required GxInterpolationType InterpolationType { get; init; } public required float FromValue { get; init; } public required float ToValue { get; init; } @@ -94,10 +96,11 @@ private class InterpolationRegisters { /// Helper method for getting the interpolations between each of the FObj /// keyframes. /// - private static LinkedList + private static ReadOnlySpan GetInterpolationsFromFObjKeys_( - IReadOnlyList keys) { - var registers = new LinkedList(); + IReadOnlyList keys, + Span buffer) { + var index = 0; float fromValue = 0; float toValue = 0; @@ -160,7 +163,7 @@ private static LinkedList } if (timeChanged && fromFrame != toFrame) { - registers.AddLast(new InterpolationRegisters { + buffer[index++] = new InterpolationRegisters { InterpolationType = interpolationType, FromValue = fromValue, ToValue = toValue, @@ -168,11 +171,11 @@ private static LinkedList ToTangent = toTangent, FromFrame = fromFrame, ToFrame = toFrame, - }); + }; } } - return registers; + return buffer[..index]; } private class FObjKey {