From: Shawdooow Date: Thu, 18 Nov 2021 22:23:41 +0000 (-0500) Subject: use MemoryMarshal instead of manual copys X-Git-Tag: v0.2.4-beta~27 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=916c614d3046187644f88f0fe8815169ec599dc2;p=jp%2Fvke.net.git use MemoryMarshal instead of manual copys --- diff --git a/vke/src/Utils.cs b/vke/src/Utils.cs index c563a86..3324d7a 100644 --- a/vke/src/Utils.cs +++ b/vke/src/Utils.cs @@ -6,6 +6,7 @@ using System.IO; using System.Linq; using System.Numerics; using System.Reflection; +using System.Runtime.InteropServices; using System.Xml.Serialization; namespace Vulkan { @@ -67,12 +68,7 @@ namespace Vulkan { /// Populate a Vector3 with values from a float array /// public static void FromFloatArray (ref Vector3 v, float[] floats) { - if (floats.Length > 0) - v.X = floats[0]; - if (floats.Length > 1) - v.Y = floats[1]; - if (floats.Length > 2) - v.Z = floats[2]; + v = MemoryMarshal.Cast(floats)[0]; } /// /// Populate a Vector4 with values from a float array @@ -136,12 +132,7 @@ namespace Vulkan { #region Extensions methods public static void ImportFloatArray (this ref Vector3 v, float[] floats) { - if (floats.Length > 0) - v.X = floats[0]; - if (floats.Length > 1) - v.Y = floats[1]; - if (floats.Length > 2) - v.Z = floats[2]; + v = MemoryMarshal.Cast(floats)[0]; } public static Vector3 Transform (this Vector3 v, ref Matrix4x4 mat, bool translate = false) { Vector4 v4 = Vector4.Transform (new Vector4 (v, translate ? 1f : 0f), mat);