Add ROSpan Equals/CompareTo/IndexOf/Contains string-like APIs with StringComparison#27319
Conversation
| return span.SequenceEqual<char>(value); | ||
| } | ||
|
|
||
| return span.ToString().Equals(value.ToString(), comparisonType); |
There was a problem hiding this comment.
return span.ToString().Equals(value.ToString(), comparisonType); [](start = 12, length = 64)
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.
Will address outside the PR (see https://github.com/dotnet/corefx/issues/27379).
| /// <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.
why not optimizing for the ordinal cases?
There was a problem hiding this comment.
Since we don't already have an optimized ordinal CompareTo (unlike the other APIs), I will address this outside the PR.
There was a problem hiding this comment.
Thanks for tracking this issue.
|
|
||
| using System.Globalization; | ||
| using System.Threading; | ||
| using Xunit; |
There was a problem hiding this comment.
in general for tests, I prefer to edit the tests in https://github.com/dotnet/corefx/blob/master/src/System.Globalization/tests/CompareInfo and inject the Span cases inside the test cases. by doing that we'll ensure the string and the span behavior is identical and in the future any added more test data will get automatically applied to both the strings and the spans
There was a problem hiding this comment.
There is some overlap here: https://github.com/dotnet/corefx/blob/master/src/System.Runtime/tests/System/StringTests.cs#L589
Also, the CompareInfo tests are testing CompareOptions, which Span APIs do not have.
There was a problem hiding this comment.
Would be better then add the span tests to the string tests you have pointed at. I just want to ensure the string and span behaving exactly same.
There was a problem hiding this comment.
That is where I borrowed the tests from. I had to make some minor adjustments which is why it doesn't seem worth the effort to move the tests back.
Also, span has specific tests that are unique to it, so this way all the span tests live in one place (and one assembly).
There was a problem hiding this comment.
I didn't mean to borrow the test but inject the span tests into the string tests. it'll pay off when adding more test cases or data to these tests. Maintaining 2 places which we need to guarantee the consistency would be hard.
For Unique Span tests, that fine to split these.
There was a problem hiding this comment.
If the string APIs start calling the span APIs instead, we would get the coverage without having to update the tests.
I can update the tests if it turns out we can't call the span APIs from the string APIs due to perf or other reason.
There was a problem hiding this comment.
|
@dotnet-bot test this please |
|
@dotnet-bot test Tizen armel Debug Build |
|
Windows x86 Release Build |
…ringComparison (dotnet/corefx#27319) * Add ROSpan Equals/CompareTo/IndexOf/Contains string-like APIs with StringComparison * Respond to recent change AsReadOnlySpan -> AsSpan * Remove the out parameter from IndexOf * Add tests and avoid allocations for StringComparison.Ordinal * Remove duplicate definition of SoftHyphen Commit migrated from dotnet/corefx@fdabc62
Part of https://github.com/dotnet/corefx/issues/21395#issuecomment-359906138
(fast span only)(fast span only)Depends on: dotnet/coreclr#16467
TODO:
Verify correctness on UnixCan we expose string.IndexOf without int matchedLengthparameter? Can we expose string.Contains withStringComparison comparisonTypeparameter? If not, these APIs cannot be implemented for portable span.cc @jkotas, @stephentoub, @KrzysztofCwalina, @tarekgh, @JeremyKuhne, @joshfree