diff --git a/PPather/Extensions/BinaryReaderExtensions.cs b/PPather/Extensions/BinaryReaderExtensions.cs index 69fc3443..c0952c75 100644 --- a/PPather/Extensions/BinaryReaderExtensions.cs +++ b/PPather/Extensions/BinaryReaderExtensions.cs @@ -1,23 +1,27 @@ using System; using System.IO; using System.Numerics; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace PPather.Extensions; public static class BinaryReaderExtensions { - public static Vector3 ReadVector3(this BinaryReader b) + [SkipLocalsInit] + public static unsafe Vector3 ReadVector3(this BinaryReader b) { - Span v3 = stackalloc float[3]; - b.Read(MemoryMarshal.Cast(v3)); - return new(v3); + Vector3 v; + Span buffer = new(&v, sizeof(Vector3)); + b.Read(buffer); + return v; + } + [SkipLocalsInit] public static Vector3 ReadVector3_XZY(this BinaryReader b) { - Span v3 = stackalloc float[3]; - b.Read(MemoryMarshal.Cast(v3)); + Vector3 v3 = ReadVector3(b); // from format // X Z -Y @@ -25,7 +29,7 @@ public static Vector3 ReadVector3_XZY(this BinaryReader b) // X Y Z (v3[1], v3[2]) = (-v3[2], v3[1]); - return new(v3); + return v3; } public static bool EOF(this BinaryReader b)