-
Couldn't load subscription status.
- Fork 4.9k
Add ROSpan Equals/CompareTo/IndexOf/Contains string-like APIs with StringComparison #27319
Changes from all commits
b10228f
67bf3a9
bec2f09
8dd0adf
23589ab
9b1ce10
06c34b4
3941a93
68feaf7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,58 @@ namespace System | |
| /// </summary> | ||
| public static partial class MemoryExtensions | ||
| { | ||
| /// <summary> | ||
| /// Returns a value indicating whether the specified <paramref name="value"/> occurs within the <paramref name="span"/>. | ||
| /// <param name="span">The source span.</param> | ||
| /// <param name="value">The value to seek within the source span.</param> | ||
| /// <param name="comparisonType">One of the enumeration values that determines how the <paramref name="span"/> and <paramref name="value"/> are compared.</param> | ||
| /// </summary> | ||
| public static bool Contains(this ReadOnlySpan<char> span, ReadOnlySpan<char> value, StringComparison comparisonType) | ||
| => (IndexOf(span, value, comparisonType) >= 0); | ||
|
|
||
| /// <summary> | ||
| /// Determines whether this <paramref name="span"/> and the specified <paramref name="value"/> span have the same characters | ||
| /// when compared using the specified <paramref name="comparisonType"/> option. | ||
| /// <param name="span">The source span.</param> | ||
| /// <param name="value">The value to compare with the source span.</param> | ||
| /// <param name="comparisonType">One of the enumeration values that determines how the <paramref name="span"/> and <paramref name="value"/> are compared.</param> | ||
| /// </summary> | ||
| public static bool Equals(this ReadOnlySpan<char> span, ReadOnlySpan<char> value, StringComparison comparisonType) | ||
| { | ||
| if (comparisonType == StringComparison.Ordinal) | ||
| { | ||
| return span.SequenceEqual<char>(value); | ||
| } | ||
|
|
||
| return span.ToString().Equals(value.ToString(), comparisonType); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Compares the specified <paramref name="span"/> and <paramref name="value"/> using the specified <paramref name="comparisonType"/>, | ||
| /// and returns an integer that indicates their relative position in the sort order. | ||
| /// <param name="span">The source span.</param> | ||
| /// <param name="value">The value to compare with the source span.</param> | ||
| /// <param name="comparisonType">One of the enumeration values that determines how the <paramref name="span"/> and <paramref name="value"/> are compared.</param> | ||
| /// </summary> | ||
| public static int CompareTo(this ReadOnlySpan<char> span, ReadOnlySpan<char> value, StringComparison comparisonType) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not optimizing for the ordinal cases? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we don't already have an optimized ordinal CompareTo (unlike the other APIs), I will address this outside the PR. Filed https://github.com/dotnet/corefx/issues/27379 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for tracking this issue. |
||
| => string.Compare(span.ToString(), value.ToString(), comparisonType); | ||
|
|
||
| /// <summary> | ||
| /// Reports the zero-based index of the first occurrence of the specified <paramref name="value"/> in the current <paramref name="span"/>. | ||
| /// <param name="span">The source span.</param> | ||
| /// <param name="value">The value to seek within the source span.</param> | ||
| /// <param name="comparisonType">One of the enumeration values that determines how the <paramref name="span"/> and <paramref name="value"/> are compared.</param> | ||
| /// </summary> | ||
| public static int IndexOf(this ReadOnlySpan<char> span, ReadOnlySpan<char> value, StringComparison comparisonType) | ||
| { | ||
| if (comparisonType == StringComparison.Ordinal) | ||
| { | ||
| return span.IndexOf<char>(value); | ||
| } | ||
|
|
||
| return span.ToString().IndexOf(value.ToString(), comparisonType); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Copies the characters from the source span into the destination, converting each character to lowercase, | ||
| /// using the casing rules of the specified culture. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have any optimization for ordinal ignore case when having ascii cases as we did in coreclr? this apply for all introduced APIs here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will address outside the PR (see https://github.com/dotnet/corefx/issues/27379).