Improve performance and safety

This commit is contained in:
2026-02-01 01:56:17 +09:00
parent 1fee890329
commit c36405645b
32 changed files with 2050 additions and 360 deletions

View File

@@ -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)