From 916c614d3046187644f88f0fe8815169ec599dc2 Mon Sep 17 00:00:00 2001 From: Shawdooow Date: Thu, 18 Nov 2021 17:23:41 -0500 Subject: [PATCH] use MemoryMarshal instead of manual copys --- vke/src/Utils.cs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) 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); -- 2.47.3