public static bool Equals <T>(T?value, T?other) { var pValue = Unsafe.AsPointer(ref value); var pOther = Unsafe.AsPointer(ref other); var size = Unsafe.SizeOf <T>(); return(BinaryEqualityComparer.Equals(pValue, pOther, size)); }
public static bool BinaryEquals <T>(this ReadOnlySpan <T> span, ReadOnlySpan <T> other) where T : unmanaged { if (span == other) { return(true); } if (span.Length != other.Length) { return(false); } fixed(T *pSpan = span, pOther = other) { var size = sizeof(T) * span.Length; return(BinaryEqualityComparer.Equals(pSpan, pOther, size)); } }
public static bool BinaryEquals <T>(this T[, , ]?array, T[, , ]?other) where T : unmanaged { if (object.ReferenceEquals(array, other)) { return(true); } if ((array is null) || (other is null)) { return(false); } if (array.Length != other.Length) { return(false); } fixed(T *pArray = array, pOther = other) { var size = sizeof(T) * array.Length; return(BinaryEqualityComparer.Equals(pArray, pOther, size)); } }
public static bool BinaryEquals <T>(this T value, T other) where T : unmanaged { return(BinaryEqualityComparer.Equals(&value, &other, sizeof(T))); }