Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit d21fa56

Browse files
AlexRadchstephentoub
authored andcommitted
Optimize string-like portable Span APIs for Ordinal and OrdinalIgnoreCase (#27905)
* Optimize Span<char>.CompareTo * Formating
1 parent 1bfca45 commit d21fa56

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/System.Memory/src/System/MemoryExtensions.Portable.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ public static bool Equals(this ReadOnlySpan<char> span, ReadOnlySpan<char> value
5151
/// <param name="value">The value to compare with the source span.</param>
5252
/// <param name="comparisonType">One of the enumeration values that determines how the <paramref name="span"/> and <paramref name="value"/> are compared.</param>
5353
/// </summary>
54-
public static int CompareTo(this ReadOnlySpan<char> span, ReadOnlySpan<char> value, StringComparison comparisonType)
55-
=> string.Compare(span.ToString(), value.ToString(), comparisonType);
54+
public static int CompareTo(this ReadOnlySpan<char> span, ReadOnlySpan<char> value, StringComparison comparisonType)
55+
=> comparisonType == StringComparison.Ordinal
56+
? span.SequenceCompareTo(value)
57+
: string.Compare(span.ToString(), value.ToString(), comparisonType);
5658

5759
/// <summary>
5860
/// Reports the zero-based index of the first occurrence of the specified <paramref name="value"/> in the current <paramref name="span"/>.

0 commit comments

Comments
 (0)