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

Conversation

@ahsonkhan
Copy link

@ahsonkhan ahsonkhan commented Feb 21, 2018

Part of https://github.com/dotnet/corefx/issues/21395#issuecomment-359906138

  • Equals
  • CompareTo
  • IndexOf (fast span only)
  • Contains (fast span only)

Depends on: dotnet/coreclr#16467

TODO:

  • Add more tests
  • Verify correctness on Unix
  • Can we expose string.IndexOf with out int matchedLength parameter? Can we expose string.Contains with StringComparison comparisonType parameter? If not, these APIs cannot be implemented for portable span.

cc @jkotas, @stephentoub, @KrzysztofCwalina, @tarekgh, @JeremyKuhne, @joshfree

@joshfree joshfree requested a review from tarekgh February 22, 2018 18:12
return span.SequenceEqual<char>(value);
}

return span.ToString().Equals(value.ToString(), comparisonType);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/// <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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not optimizing for the ordinal cases?

Copy link
Author

Choose a reason for hiding this comment

The 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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tracking this issue.


using System.Globalization;
using System.Threading;
using Xunit;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joshfree joshfree removed the blocked Issue/PR is blocked on something - see comments label Feb 27, 2018
@ahsonkhan
Copy link
Author

@dotnet-bot test this please

@ahsonkhan
Copy link
Author

@dotnet-bot test Tizen armel Debug Build

@ahsonkhan
Copy link
Author

Windows x86 Release Build
Windows.10.Amd64.Open-Release-x86
https://mc.dot.net/#/user/ahsonkhan/pr~2Fjenkins~2Fdotnet~2Fcorefx~2Fmaster~2F/test~2Ffunctional~2Fcli~2F/3941a9303e4dd657a0db10fbfaf4d751a67ed57d/workItem/System.Net.Http.Functional.Tests
System.Net.Http.Functional.Tests.HttpCookieProtocolTests/GetAsyncWithRedirect_SetCookieContainer_CorrectCookiesSent

System.Net.Http.HttpRequestException : An error occurred while sending the request.
---- System.Net.Http.WinHttpException : The server returned an invalid or unrecognized response
   at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts) in D:\j\workspace\windows-TGrou---f8ac6754\src\System.Net.Http\src\System\Net\Http\HttpClient.cs:line 469
   at System.Net.Http.Functional.Tests.HttpCookieProtocolTests.<GetAsyncWithRedirect_SetCookieContainer_CorrectCookiesSent>b__15_0(Uri url) in D:\j\workspace\windows-TGrou---f8ac6754\src\System.Net.Http\tests\FunctionalTests\HttpCookieProtocolTests.cs:line 319
   at System.Net.Test.Common.LoopbackServer.<>c__DisplayClass11_0.<<CreateClientAndServerAsync>b__0>d.MoveNext() in D:\j\workspace\windows-TGrou---f8ac6754\src\Common\tests\System\Net\Http\LoopbackServer.cs:line 84
--- End of stack trace from previous location where exception was thrown ---
   at System.Net.Test.Common.LoopbackServer.CreateServerAsync(Func`2 funcAsync, Options options) in D:\j\workspace\windows-TGrou---f8ac6754\src\Common\tests\System\Net\Http\LoopbackServer.cs:line 67
   at System.Net.Http.Functional.Tests.HttpCookieProtocolTests.GetAsyncWithRedirect_SetCookieContainer_CorrectCookiesSent() in D:\j\workspace\windows-TGrou---f8ac6754\src\System.Net.Http\tests\FunctionalTests\HttpCookieProtocolTests.cs:line 305
--- End of stack trace from previous location where exception was thrown ---
----- Inner Stack Trace -----
   at System.Threading.Tasks.RendezvousAwaitable`1.GetResult() in D:\j\workspace\windows-TGrou---f8ac6754\src\Common\src\System\Threading\Tasks\RendezvousAwaitable.cs:line 62
   at System.Net.Http.WinHttpHandler.StartRequest(WinHttpRequestState state) in D:\j\workspace\windows-TGrou---f8ac6754\src\System.Net.Http.WinHttpHandler\src\System\Net\Http\WinHttpHandler.cs:line 863

https://github.com/dotnet/corefx/issues/27390

@ahsonkhan ahsonkhan merged commit fdabc62 into dotnet:master Feb 28, 2018
@ahsonkhan ahsonkhan deleted the SpanStringAPIs branch February 28, 2018 19:09
@karelz karelz added this to the 2.1.0 milestone Mar 10, 2018
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
…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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants