Repository: dotnet/runtime
File: src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.cs (C#)

Code before:
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        [OverloadResolutionPriority(-1)]
        public static int IndexOfAnyExceptInRange<T>(this Span<T> span, T lowInclusive, T highInclusive) where T : IComparable<T> =>
            IndexOfAnyExceptInRange((ReadOnlySpan<T>)span, lowInclusive, highInclusive);

        /// <summary>Searches for the first index of any value outside of the range between <paramref name="lowInclusive"/> and <paramref name="highInclusive"/>, inclusive.</summary>
        /// <typeparam name="T">The type of the span and values.</typeparam>
        /// <param name="span">The span to search.</param>
        /// <param name="lowInclusive">A lower bound, inclusive, of the excluded range.</param>
        /// <param name="highInclusive">A upper bound, inclusive, of the excluded range.</param>
        /// <returns>
        /// The index in the span of the first occurrence of any value outside of the specified range.
        /// If all of the values are inside of the specified range, returns -1.
        /// </returns>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static int IndexOfAnyExceptInRange<T>(this ReadOnlySpan<T> span, T lowInclusive, T highInclusive) where T : IComparable<T>
        {
            if (lowInclusive is null || highInclusive is null)
            {
                ThrowNullLowHighInclusive(lowInclusive, highInclusive);
            }

            // When highInclusive < lowInclusive, the range is invalid and all values are outside it.
            if (lowInclusive.CompareTo(highInclusive) > 0)
            {
                return span.Length > 0 ? 0 : -1;
            }

            if (Vector128.IsHardwareAccelerated)
            {
                if (lowInclusive is byte or sbyte)
                {
                    return SpanHelpers.IndexOfAnyExceptInRangeUnsignedNumber(
                        ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)),
                        Unsafe.BitCast<T, byte>(lowInclusive),
                        Unsafe.BitCast<T, byte>(highInclusive),
                        span.Length);
                }

                if (lowInclusive is short or ushort or char)
                {
                    return SpanHelpers.IndexOfAnyExceptInRangeUnsignedNumber(
                        ref Unsafe.As<T, ushort>(ref MemoryMarshal.GetReference(span)),
                        Unsafe.BitCast<T, ushort>(lowInclusive),
                        Unsafe.BitCast<T, ushort>(highInclusive),
                        span.Length);
                }

                if (lowInclusive is int or uint || (IntPtr.Size == 4 && (lowInclusive is nint or nuint)))
                {
                    return SpanHelpers.IndexOfAnyExceptInRangeUnsignedNumber(

Review comment (suggestion):
@copilot, nit:
```suggestion
                return span.IsEmpty ? -1 : 0;
```
and similarly using IsEmpty in the other change where this pattern shows up.

Code after:
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        [OverloadResolutionPriority(-1)]
        public static int IndexOfAnyExceptInRange<T>(this Span<T> span, T lowInclusive, T highInclusive) where T : IComparable<T> =>
            IndexOfAnyExceptInRange((ReadOnlySpan<T>)span, lowInclusive, highInclusive);

        /// <summary>Searches for the first index of any value outside of the range between <paramref name="lowInclusive"/> and <paramref name="highInclusive"/>, inclusive.</summary>
        /// <typeparam name="T">The type of the span and values.</typeparam>
        /// <param name="span">The span to search.</param>
        /// <param name="lowInclusive">A lower bound, inclusive, of the excluded range.</param>
        /// <param name="highInclusive">A upper bound, inclusive, of the excluded range.</param>
        /// <returns>
        /// The index in the span of the first occurrence of any value outside of the specified range.
        /// If all of the values are inside of the specified range, returns -1.
        /// </returns>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static int IndexOfAnyExceptInRange<T>(this ReadOnlySpan<T> span, T lowInclusive, T highInclusive) where T : IComparable<T>
        {
            if (lowInclusive is null || highInclusive is null)
            {
                ThrowNullLowHighInclusive(lowInclusive, highInclusive);
            }

            // When highInclusive < lowInclusive, the range is invalid and all values are outside it.
            if (lowInclusive.CompareTo(highInclusive) > 0)
            {
                return span.IsEmpty ? -1 : 0;
            }

            if (Vector128.IsHardwareAccelerated)
            {
                if (lowInclusive is byte or sbyte)
                {
                    return SpanHelpers.IndexOfAnyExceptInRangeUnsignedNumber(
                        ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)),
                        Unsafe.BitCast<T, byte>(lowInclusive),
                        Unsafe.BitCast<T, byte>(highInclusive),
                        span.Length);
                }

                if (lowInclusive is short or ushort or char)
                {
                    return SpanHelpers.IndexOfAnyExceptInRangeUnsignedNumber(
                        ref Unsafe.As<T, ushort>(ref MemoryMarshal.GetReference(span)),
                        Unsafe.BitCast<T, ushort>(lowInclusive),
                        Unsafe.BitCast<T, ushort>(highInclusive),
                        span.Length);
                }

                if (lowInclusive is int or uint || (IntPtr.Size == 4 && (lowInclusive is nint or nuint)))
                {
                    return SpanHelpers.IndexOfAnyExceptInRangeUnsignedNumber(