]> O.S.I.I.S - jp/vke.net.git/commitdiff
Use Unsafe since its faster
authorShawdooow <banhammer1915@gmail.com>
Fri, 19 Nov 2021 20:37:59 +0000 (15:37 -0500)
committerj-p <jp_bruyere@hotmail.com>
Sat, 20 Nov 2021 21:26:59 +0000 (22:26 +0100)
vke/src/Utils.cs

index 3324d7aef945b04902562473a777ca39476534b4..853067ece25e82a15d8edee5b217724bbe0e36d4 100644 (file)
@@ -6,6 +6,7 @@ using System.IO;
 using System.Linq;
 using System.Numerics;
 using System.Reflection;
+using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Xml.Serialization;
 
@@ -68,7 +69,7 @@ namespace Vulkan {
                /// Populate a Vector3 with values from a float array
                /// </summary>
                public static void FromFloatArray (ref Vector3 v, float[] floats) {
-                       v = MemoryMarshal.Cast<float, Vector3>(floats)[0];
+                       v = Unsafe.As<float[], Vector3[]>(ref floats)[0];
                }
                /// <summary>
                /// Populate a Vector4 with values from a float array
@@ -132,7 +133,7 @@ namespace Vulkan {
 
                #region Extensions methods
                public static void ImportFloatArray (this ref Vector3 v, float[] floats) {
-                       v = MemoryMarshal.Cast<float, Vector3>(floats)[0];
+                       v = Unsafe.As<float[], Vector3[]>(ref 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);