]> O.S.I.I.S - jp/vke.net.git/commitdiff
use MemoryMarshal instead of manual copys
authorShawdooow <banhammer1915@gmail.com>
Thu, 18 Nov 2021 22:23:41 +0000 (17:23 -0500)
committerj-p <jp_bruyere@hotmail.com>
Sat, 20 Nov 2021 21:26:59 +0000 (22:26 +0100)
vke/src/Utils.cs

index c563a867af823abd5144549e8823f53b1cd0b891..3324d7aef945b04902562473a777ca39476534b4 100644 (file)
@@ -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
                /// </summary>
                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<float, Vector3>(floats)[0];
                }
                /// <summary>
                /// 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<float, Vector3>(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);