Skip to content

Commit

Permalink
Use .TryGetSpan on sequences instead of type checks to forward sequen…
Browse files Browse the repository at this point in the history
…ce comparison for arrays and lists (#97004)
  • Loading branch information
neon-sunset authored Jan 18, 2024
1 parent 29a35b6 commit 957ab2f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/libraries/System.Linq/src/System/Linq/SequenceEqual.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public static bool SequenceEqual<TSource>(this IEnumerable<TSource> first, IEnum

if (first is ICollection<TSource> firstCol && second is ICollection<TSource> secondCol)
{
if (first is TSource[] firstArray && second is TSource[] secondArray)
if (first.TryGetSpan(out ReadOnlySpan<TSource> firstSpan) && second.TryGetSpan(out ReadOnlySpan<TSource> secondSpan))
{
return ((ReadOnlySpan<TSource>)firstArray).SequenceEqual(secondArray, comparer);
return firstSpan.SequenceEqual(secondSpan, comparer);
}

if (firstCol.Count != secondCol.Count)
Expand Down

0 comments on commit 957ab2f

Please sign in to comment.