Optimize e84b5410ec to use faster code path on common math types

#3499
This commit is contained in:
Wojtek Figat
2026-02-03 23:00:36 +01:00
parent e84b5410ec
commit 9a44902949
16 changed files with 128 additions and 16 deletions

View File

@@ -11,7 +11,7 @@ namespace FlaxEngine
#if FLAX_EDITOR
[System.ComponentModel.TypeConverter(typeof(TypeConverters.ColorConverter))]
#endif
partial struct Color
partial struct Color : Json.ICustomValueEquals
{
/// <summary>
/// The size of the <see cref="Color" /> type, in bytes.
@@ -196,6 +196,13 @@ namespace FlaxEngine
A = values[3];
}
/// <inheritdoc />
public bool ValueEquals(object other)
{
var o = (Color)other;
return Equals(ref o);
}
/// <inheritdoc />
public override bool Equals(object value)
{

View File

@@ -65,7 +65,7 @@ namespace FlaxEngine
#if FLAX_EDITOR
[System.ComponentModel.TypeConverter(typeof(TypeConverters.Double2Converter))]
#endif
partial struct Double2 : IEquatable<Double2>, IFormattable
partial struct Double2 : IEquatable<Double2>, IFormattable, Json.ICustomValueEquals
{
private static readonly string _formatString = "X:{0:F2} Y:{1:F2}";
@@ -1574,6 +1574,13 @@ namespace FlaxEngine
}
}
/// <inheritdoc />
public bool ValueEquals(object other)
{
var o = (Double2)other;
return Equals(ref o);
}
/// <summary>
/// Determines whether the specified <see cref="Double2" /> is equal to this instance.
/// </summary>

View File

@@ -66,7 +66,7 @@ namespace FlaxEngine
#if FLAX_EDITOR
[System.ComponentModel.TypeConverter(typeof(TypeConverters.Double3Converter))]
#endif
partial struct Double3 : IEquatable<Double3>, IFormattable
partial struct Double3 : IEquatable<Double3>, IFormattable, Json.ICustomValueEquals
{
private static readonly string _formatString = "X:{0:F2} Y:{1:F2} Z:{2:F2}";
@@ -1872,6 +1872,13 @@ namespace FlaxEngine
}
}
/// <inheritdoc />
public bool ValueEquals(object other)
{
var o = (Double3)other;
return Equals(ref o);
}
/// <summary>
/// Determines whether the specified <see cref="Double3" /> is equal to this instance.
/// </summary>

View File

@@ -66,7 +66,7 @@ namespace FlaxEngine
#if FLAX_EDITOR
[System.ComponentModel.TypeConverter(typeof(TypeConverters.Double4Converter))]
#endif
partial struct Double4 : IEquatable<Double4>, IFormattable
partial struct Double4 : IEquatable<Double4>, IFormattable, Json.ICustomValueEquals
{
private static readonly string _formatString = "X:{0:F2} Y:{1:F2} Z:{2:F2} W:{3:F2}";
@@ -1372,6 +1372,13 @@ namespace FlaxEngine
}
}
/// <inheritdoc />
public bool ValueEquals(object other)
{
var o = (Double4)other;
return Equals(ref o);
}
/// <summary>
/// Determines whether the specified <see cref="Double4" /> is equal to this instance.
/// </summary>

View File

@@ -60,7 +60,7 @@ namespace FlaxEngine
#if FLAX_EDITOR
[System.ComponentModel.TypeConverter(typeof(TypeConverters.Float2Converter))]
#endif
partial struct Float2 : IEquatable<Float2>, IFormattable
partial struct Float2 : IEquatable<Float2>, IFormattable, Json.ICustomValueEquals
{
private static readonly string _formatString = "X:{0:F2} Y:{1:F2}";
@@ -1650,6 +1650,13 @@ namespace FlaxEngine
}
}
/// <inheritdoc />
public bool ValueEquals(object other)
{
var o = (Float2)other;
return Equals(ref o);
}
/// <summary>
/// Determines whether the specified <see cref="Float2" /> is equal to this instance.
/// </summary>

View File

@@ -60,7 +60,7 @@ namespace FlaxEngine
#if FLAX_EDITOR
[System.ComponentModel.TypeConverter(typeof(TypeConverters.Float3Converter))]
#endif
partial struct Float3 : IEquatable<Float3>, IFormattable
partial struct Float3 : IEquatable<Float3>, IFormattable, Json.ICustomValueEquals
{
private static readonly string _formatString = "X:{0:F2} Y:{1:F2} Z:{2:F2}";
@@ -1904,6 +1904,13 @@ namespace FlaxEngine
}
}
/// <inheritdoc />
public bool ValueEquals(object other)
{
var o = (Float3)other;
return Equals(ref o);
}
/// <summary>
/// Determines whether the specified <see cref="Float3" /> is equal to this instance.
/// </summary>

View File

@@ -60,7 +60,7 @@ namespace FlaxEngine
#if FLAX_EDITOR
[System.ComponentModel.TypeConverter(typeof(TypeConverters.Float4Converter))]
#endif
partial struct Float4 : IEquatable<Float4>, IFormattable
partial struct Float4 : IEquatable<Float4>, IFormattable, Json.ICustomValueEquals
{
private static readonly string _formatString = "X:{0:F2} Y:{1:F2} Z:{2:F2} W:{3:F2}";
@@ -1412,6 +1412,13 @@ namespace FlaxEngine
}
}
/// <inheritdoc />
public bool ValueEquals(object other)
{
var o = (Float4)other;
return Equals(ref o);
}
/// <summary>
/// Determines whether the specified <see cref="Float4" /> is equal to this instance.
/// </summary>

View File

@@ -14,7 +14,7 @@ namespace FlaxEngine
#if FLAX_EDITOR
[System.ComponentModel.TypeConverter(typeof(TypeConverters.Int2Converter))]
#endif
partial struct Int2 : IEquatable<Int2>, IFormattable
partial struct Int2 : IEquatable<Int2>, IFormattable, Json.ICustomValueEquals
{
private static readonly string _formatString = "X:{0} Y:{1}";
@@ -940,6 +940,13 @@ namespace FlaxEngine
}
}
/// <inheritdoc />
public bool ValueEquals(object other)
{
var o = (Int2)other;
return Equals(ref o);
}
/// <summary>
/// Determines whether the specified <see cref="Int2" /> is equal to this instance.
/// </summary>

View File

@@ -14,7 +14,7 @@ namespace FlaxEngine
#if FLAX_EDITOR
[System.ComponentModel.TypeConverter(typeof(TypeConverters.Int3Converter))]
#endif
partial struct Int3 : IEquatable<Int3>, IFormattable
partial struct Int3 : IEquatable<Int3>, IFormattable, Json.ICustomValueEquals
{
private static readonly string _formatString = "X:{0} Y:{1} Z:{2}";
@@ -1023,6 +1023,13 @@ namespace FlaxEngine
}
}
/// <inheritdoc />
public bool ValueEquals(object other)
{
var o = (Int3)other;
return Equals(ref o);
}
/// <summary>
/// Determines whether the specified <see cref="Int3" /> is equal to this instance.
/// </summary>

View File

@@ -14,7 +14,7 @@ namespace FlaxEngine
#if FLAX_EDITOR
[System.ComponentModel.TypeConverter(typeof(TypeConverters.Int4Converter))]
#endif
partial struct Int4 : IEquatable<Int4>, IFormattable
partial struct Int4 : IEquatable<Int4>, IFormattable, Json.ICustomValueEquals
{
private static readonly string _formatString = "X:{0} Y:{1} Z:{2} W:{3}";
@@ -881,6 +881,13 @@ namespace FlaxEngine
}
}
/// <inheritdoc />
public bool ValueEquals(object other)
{
var o = (Int4)other;
return Equals(ref o);
}
/// <summary>
/// Determines whether the specified <see cref="Int4" /> is equal to this instance.
/// </summary>

View File

@@ -60,7 +60,7 @@ namespace FlaxEngine
#if FLAX_EDITOR
[System.ComponentModel.TypeConverter(typeof(TypeConverters.QuaternionConverter))]
#endif
partial struct Quaternion : IEquatable<Quaternion>, IFormattable
partial struct Quaternion : IEquatable<Quaternion>, IFormattable, Json.ICustomValueEquals
{
private static readonly string _formatString = "X:{0:F2} Y:{1:F2} Z:{2:F2} W:{3:F2}";
@@ -1681,6 +1681,13 @@ namespace FlaxEngine
}
}
/// <inheritdoc />
public bool ValueEquals(object other)
{
var o = (Quaternion)other;
return Equals(ref o);
}
/// <summary>
/// Tests whether one quaternion is near another quaternion.
/// </summary>

View File

@@ -6,7 +6,7 @@ using System.Runtime.CompilerServices;
namespace FlaxEngine
{
partial struct Rectangle : IEquatable<Rectangle>
partial struct Rectangle : IEquatable<Rectangle>, Json.ICustomValueEquals
{
/// <summary>
/// A <see cref="Rectangle"/> which represents an empty space.
@@ -523,6 +523,13 @@ namespace FlaxEngine
}
}
/// <inheritdoc />
public bool ValueEquals(object other)
{
var o = (Rectangle)other;
return Equals(ref o);
}
/// <inheritdoc />
public override string ToString()
{

View File

@@ -16,7 +16,7 @@ using System.Runtime.InteropServices;
namespace FlaxEngine
{
[Serializable]
partial struct Transform : IEquatable<Transform>, IFormattable
partial struct Transform : IEquatable<Transform>, IFormattable, Json.ICustomValueEquals
{
private static readonly string _formatString = "Translation:{0} Orientation:{1} Scale:{2}";
@@ -673,6 +673,13 @@ namespace FlaxEngine
}
}
/// <inheritdoc />
public bool ValueEquals(object other)
{
var o = (Transform)other;
return Equals(ref o);
}
/// <summary>
/// Tests whether one transform is near another transform.
/// </summary>

View File

@@ -73,7 +73,7 @@ namespace FlaxEngine
#if FLAX_EDITOR
[System.ComponentModel.TypeConverter(typeof(TypeConverters.Vector2Converter))]
#endif
public unsafe partial struct Vector2 : IEquatable<Vector2>, IFormattable
public unsafe partial struct Vector2 : IEquatable<Vector2>, IFormattable, Json.ICustomValueEquals
{
private static readonly string _formatString = "X:{0:F2} Y:{1:F2}";
@@ -1774,6 +1774,13 @@ namespace FlaxEngine
}
}
/// <inheritdoc />
public bool ValueEquals(object other)
{
var o = (Vector2)other;
return Equals(ref o);
}
/// <summary>
/// Determines whether the specified <see cref="Vector2" /> is equal to this instance.
/// </summary>

View File

@@ -73,7 +73,7 @@ namespace FlaxEngine
#if FLAX_EDITOR
[System.ComponentModel.TypeConverter(typeof(TypeConverters.Vector3Converter))]
#endif
public unsafe partial struct Vector3 : IEquatable<Vector3>, IFormattable
public unsafe partial struct Vector3 : IEquatable<Vector3>, IFormattable, Json.ICustomValueEquals
{
private static readonly string _formatString = "X:{0:F2} Y:{1:F2} Z:{2:F2}";
@@ -2133,6 +2133,13 @@ namespace FlaxEngine
}
}
/// <inheritdoc />
public bool ValueEquals(object other)
{
var o = (Vector3)other;
return Equals(ref o);
}
/// <summary>
/// Determines whether the specified <see cref="Vector3" /> is equal to this instance.
/// </summary>

View File

@@ -72,7 +72,7 @@ namespace FlaxEngine
#if FLAX_EDITOR
[System.ComponentModel.TypeConverter(typeof(TypeConverters.Vector4Converter))]
#endif
public partial struct Vector4 : IEquatable<Vector4>, IFormattable
public partial struct Vector4 : IEquatable<Vector4>, IFormattable, Json.ICustomValueEquals
{
private static readonly string _formatString = "X:{0:F2} Y:{1:F2} Z:{2:F2} W:{3:F2}";
@@ -1499,6 +1499,13 @@ namespace FlaxEngine
}
}
/// <inheritdoc />
public bool ValueEquals(object other)
{
var o = (Vector4)other;
return Equals(ref o);
}
/// <summary>
/// Determines whether the specified <see cref="Vector4" /> is equal to this instance.
/// </summary>