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

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

        /// <summary>Searches for the last 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 last 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 LastIndexOfAnyExceptInRange<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 : span.Length - 1;
            }

            if (Vector128.IsHardwareAccelerated)
            {
                if (lowInclusive is byte or sbyte)
                {
                    return SpanHelpers.LastIndexOfAnyExceptInRangeUnsignedNumber(
                        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.LastIndexOfAnyExceptInRangeUnsignedNumber(
                        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.LastIndexOfAnyExceptInRangeUnsignedNumber(

Review comment (suggestion):
```suggestion
                return span.Length - 1;
```

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

        /// <summary>Searches for the last 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 last 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 LastIndexOfAnyExceptInRange<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 - 1;
            }

            if (Vector128.IsHardwareAccelerated)
            {
                if (lowInclusive is byte or sbyte)
                {
                    return SpanHelpers.LastIndexOfAnyExceptInRangeUnsignedNumber(
                        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.LastIndexOfAnyExceptInRangeUnsignedNumber(
                        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.LastIndexOfAnyExceptInRangeUnsignedNumber(