mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-22 19:28:48 +00:00
perf: use UnsafeUtility for Unity<->System conversions
This commit is contained in:
parent
183033cc80
commit
a09492d418
@ -1,6 +1,7 @@
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Drawing;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Unity.Collections.LowLevel.Unsafe;
|
||||
using UnityEngine;
|
||||
|
||||
namespace X10D.Unity.Drawing;
|
||||
@ -31,6 +32,6 @@ public static class PointExtensions
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vector2Int ToUnityVector2Int(this Point value)
|
||||
{
|
||||
return new Vector2Int(value.X, value.Y);
|
||||
return UnsafeUtility.As<Point, Vector2Int>(ref value);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Drawing;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Unity.Collections.LowLevel.Unsafe;
|
||||
using UnityEngine;
|
||||
using X10D.Drawing;
|
||||
using X10D.Unity.Numerics;
|
||||
@ -38,6 +39,6 @@ public static class PointFExtensions
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vector2 ToUnityVector2(this PointF point)
|
||||
{
|
||||
return new Vector2(point.X, point.Y);
|
||||
return UnsafeUtility.As<PointF, Vector2>(ref point);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Drawing;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Unity.Collections.LowLevel.Unsafe;
|
||||
using UnityEngine;
|
||||
|
||||
namespace X10D.Unity.Drawing;
|
||||
@ -19,6 +20,6 @@ public static class RectExtensions
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static RectangleF ToSystemRectangleF(this Rect rectangle)
|
||||
{
|
||||
return new RectangleF(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
|
||||
return UnsafeUtility.As<Rect, RectangleF>(ref rectangle);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Drawing;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Unity.Collections.LowLevel.Unsafe;
|
||||
using UnityEngine;
|
||||
|
||||
namespace X10D.Unity.Drawing;
|
||||
@ -19,7 +20,7 @@ public static class RectIntExtensions
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Rectangle ToSystemRectangle(this RectInt rectangle)
|
||||
{
|
||||
return new Rectangle(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
|
||||
return UnsafeUtility.As<RectInt, Rectangle>(ref rectangle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -31,6 +32,7 @@ public static class RectIntExtensions
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static RectangleF ToSystemRectangleF(this RectInt rectangle)
|
||||
{
|
||||
return new RectangleF(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
|
||||
// REMARKS: implicit conversion already exists, this method is largely pointless
|
||||
return rectangle.ToSystemRectangle();
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Drawing;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Unity.Collections.LowLevel.Unsafe;
|
||||
using UnityEngine;
|
||||
|
||||
namespace X10D.Unity.Drawing;
|
||||
@ -31,6 +32,6 @@ public static class RectangleExtensions
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static RectInt ToUnityRectInt(this Rectangle rectangle)
|
||||
{
|
||||
return new RectInt(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
|
||||
return UnsafeUtility.As<Rectangle, RectInt>(ref rectangle);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Drawing;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Unity.Collections.LowLevel.Unsafe;
|
||||
using UnityEngine;
|
||||
|
||||
namespace X10D.Unity.Drawing;
|
||||
@ -19,7 +20,8 @@ public static class SizeExtensions
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vector2 ToUnityVector2(this Size size)
|
||||
{
|
||||
return new Vector2(size.Width, size.Height);
|
||||
// REMARKS: implicit conversion already exists, this method is largely pointless
|
||||
return size.ToUnityVector2Int();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -31,6 +33,6 @@ public static class SizeExtensions
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vector2Int ToUnityVector2Int(this Size size)
|
||||
{
|
||||
return new Vector2Int(size.Width, size.Height);
|
||||
return UnsafeUtility.As<Size, Vector2Int>(ref size);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Drawing;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Unity.Collections.LowLevel.Unsafe;
|
||||
using UnityEngine;
|
||||
|
||||
namespace X10D.Unity.Drawing;
|
||||
@ -19,6 +20,6 @@ public static class SizeFExtensions
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vector2 ToUnityVector2(this SizeF size)
|
||||
{
|
||||
return new Vector2(size.Width, size.Height);
|
||||
return UnsafeUtility.As<SizeF, Vector2>(ref size);
|
||||
}
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ public static class Vector2Extensions
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static PointF ToSystemPointF(this Vector2 vector)
|
||||
{
|
||||
return new PointF(vector.x, vector.y);
|
||||
return UnsafeUtility.As<Vector2, PointF>(ref vector);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -124,7 +124,7 @@ public static class Vector2Extensions
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static SizeF ToSystemSizeF(this Vector2 vector)
|
||||
{
|
||||
return new SizeF(vector.x, vector.y);
|
||||
return UnsafeUtility.As<Vector2, SizeF>(ref vector);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
Loading…
Reference in New Issue
Block a user