src/AnvilPacker/Util/Mem.cs
/// <summary> Returns whether all elements in the array are equal the specified value. </summary>
Returns whether all elements in the array are equal the specified value.
Returns whether all elements in the array are equal the specified value .
public static bool AllEquals<T>(ReadOnlySpan<T> span, T value) where T : IEquatable<T>
        {
            if (Vector.IsHardwareAccelerated && !RuntimeHelpers.IsReferenceOrContainsReferences<T>()) {
                if (Unsafe.SizeOf<T>() == 1) {
                    return AllEqualsSimd(
                        ref Unsafe.As<T, byte>(ref GetRef(span)),
                        Unsafe.As<T, byte>(ref value),
                        span.Length
                    );
                }
                if (Unsafe.SizeOf<T>() == 2) {
                    return AllEqualsSimd(
                        ref Unsafe.As<T, short>(ref GetRef(span)),
                        Unsafe.As<T, short>(ref value),
                        span.Length
                    );
                }
                if (Unsafe.SizeOf<T>() == 4) {
                    return AllEqualsSimd(
                        ref Unsafe.As<T, int>(ref GetRef(span)),
                        Unsafe.As<T, int>(ref value),
                        span.Length
                    );
                }
                if (Unsafe.SizeOf<T>() == 8) {
                    return AllEqualsSimd(
                        ref Unsafe.As<T, long>(ref GetRef(span)),
                        Unsafe.As<T, long>(ref value),
                        span.Length
                    );
                }
            }
            ref T ptr = ref GetRef(span);
            ref T endPtr = ref Unsafe.Add(ref ptr, span.Length);
            while (Unsafe.IsAddressLessThan(ref ptr, ref endPtr)) {
                if (!ptr.Equals(value)) {
                    return false;
                }
                ptr = ref Unsafe.Add(ref ptr, 1);
            }
            return true;
        }
public static bool AllEquals < T > ( ReadOnlySpan < T > span , T value ) where T : IEquatable < T > { if ( Vector . IsHardwareAccelerated && ! RuntimeHelpers . IsReferenceOrContainsReferences < T > ( ) ) { if ( Unsafe . SizeOf < T > ( ) == 1 ) { return AllEqualsSimd ( ref Unsafe . As < T , byte > ( ref GetRef ( span ) ) , Unsafe . As < T , byte > ( ref value ) , span . Length ) ; } if ( Unsafe . SizeOf < T > ( ) == 2 ) { return AllEqualsSimd ( ref Unsafe . As < T , short > ( ref GetRef ( span ) ) , Unsafe . As < T , short > ( ref value ) , span . Length ) ; } if ( Unsafe . SizeOf < T > ( ) == 4 ) { return AllEqualsSimd ( ref Unsafe . As < T , int > ( ref GetRef ( span ) ) , Unsafe . As < T , int > ( ref value ) , span . Length ) ; } if ( Unsafe . SizeOf < T > ( ) == 8 ) { return AllEqualsSimd ( ref Unsafe . As < T , long > ( ref GetRef ( span ) ) , Unsafe . As < T , long > ( ref value ) , span . Length ) ; } } ref T ptr = ref GetRef ( span ) ; ref T endPtr = ref Unsafe . Add ( ref ptr , span . Length ) ; while ( Unsafe . IsAddressLessThan ( ref ptr , ref endPtr ) ) { if ( ! ptr . Equals ( value ) ) { return false ; } ptr = ref Unsafe . Add ( ref ptr , 1 ) ; } return true ; }
Returns whether all elements in the array are equal the specified value.
Returns whether all elements in the array are equal the specified value .
span
ReadOnlySpan<T>
value
T