Improve performance and safety
This commit is contained in:
@@ -136,7 +136,7 @@ public unsafe struct UniquePtr<T> : IEquatable<UniquePtr<T>>
|
||||
}
|
||||
}
|
||||
|
||||
public ref struct Ref<T>
|
||||
public ref struct Ref<T> : IEquatable<Ref<T>>
|
||||
{
|
||||
private ref T _value;
|
||||
|
||||
@@ -150,6 +150,11 @@ public ref struct Ref<T>
|
||||
return ref _value;
|
||||
}
|
||||
|
||||
public bool Equals(Ref<T> other)
|
||||
{
|
||||
return Unsafe.AreSame(ref _value, ref other._value);
|
||||
}
|
||||
|
||||
[Obsolete("Equals() on Ref will always throw an exception. Use the equality operator instead.")]
|
||||
#pragma warning disable CS0809 // Obsolete member overrides non-obsolete member
|
||||
public override bool Equals(object? obj)
|
||||
@@ -166,7 +171,7 @@ public ref struct Ref<T>
|
||||
|
||||
public static bool operator ==(Ref<T> left, Ref<T> right)
|
||||
{
|
||||
return Unsafe.AreSame(ref left._value, ref right._value);
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(Ref<T> left, Ref<T> right)
|
||||
|
||||
Reference in New Issue
Block a user