Skip to content

Commit 957ab2f

Browse files
authored
Use .TryGetSpan on sequences instead of type checks to forward sequence comparison for arrays and lists (#97004)
1 parent 29a35b6 commit 957ab2f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/libraries/System.Linq/src/System/Linq/SequenceEqual.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ public static bool SequenceEqual<TSource>(this IEnumerable<TSource> first, IEnum
2424

2525
if (first is ICollection<TSource> firstCol && second is ICollection<TSource> secondCol)
2626
{
27-
if (first is TSource[] firstArray && second is TSource[] secondArray)
27+
if (first.TryGetSpan(out ReadOnlySpan<TSource> firstSpan) && second.TryGetSpan(out ReadOnlySpan<TSource> secondSpan))
2828
{
29-
return ((ReadOnlySpan<TSource>)firstArray).SequenceEqual(secondArray, comparer);
29+
return firstSpan.SequenceEqual(secondSpan, comparer);
3030
}
3131

3232
if (firstCol.Count != secondCol.Count)

0 commit comments

Comments
 (0)