-
Notifications
You must be signed in to change notification settings - Fork 4.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds SpanSplitEnumerator
#104534
base: main
Are you sure you want to change the base?
Adds SpanSplitEnumerator
#104534
Conversation
Note regarding the
|
1 similar comment
Note regarding the
|
src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.Split.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.Split.cs
Outdated
Show resolved
Hide resolved
|
||
namespace System.SpanTests | ||
{ | ||
public static partial class ReadOnlySpanTests |
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.
Can you make the existing string.Split test cases work for this as well, validating that the new Split produces the same splits as string.Split does?
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.
I may not be understanding completely, do you mean:
- Find the test cases for
string.Split
- Move them into
tests/ReadOnlySpan/Split.char.cs
or just add an Assert to the custom AssertEquals method in this file that does an additionalstring.Split
to ensure the result of theSpanSplitEnumerator
andstring.Split
align?
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.
just add an Assert to the custom AssertEquals method in this file that does an additional string.Split to ensure the result of the SpanSplitEnumerator and string.Split align?
This :)
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.
Oh, wait, no, I misread what you wrote. I meant the equivalent of this:
runtime/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/String.SplitTests.cs
Lines 9 to 10 in 101c0da
// These tests validate both String.Split and MemoryExtensions.Split, as they have equivalent semantics, with the | |
// former creating a new array to store the results and the latter writing the results into a supplied span. |
Augmenting those tests to test these overloads as well, rather than duplicating a ton of tests.
@@ -191,6 +191,7 @@ | |||
<Compile Include="ReadOnlySpan\SequenceEqual.long.cs" /> | |||
<Compile Include="ReadOnlySpan\SequenceEqual.T.cs" /> | |||
<Compile Include="ReadOnlySpan\Slice.cs" /> | |||
<Compile Include="ReadOnlySpan\Split.char.cs" /> |
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.
What about T other than char?
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.
The PR was still in draft, so was still going to work on more exhaustive tests. What/How many other types do you think would be reasonable to test? Not sure if this is a good idea, but I could generalise the tests so it casts the incoming string of the existing tests to ReadOnlySpan<byte/long/etc>
. Though of course this means you are realistically testing the same exact data, just with the types differing.
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.
What/How many other types do you think would be reasonable to test?
Just basic validation of an assortment of other types, e.g. byte, int, a custom reference type, and a custom value type.
src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.Split.cs
Outdated
Show resolved
Hide resolved
|
||
private int _startCurrent = 0; | ||
private int _endCurrent = 0; | ||
private int _startNext = 0; |
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.
Is _startNext needed rather than just updating _span to be the remainder to be searched?
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.
As with https://github.com/dotnet/runtime/pull/104534/files#r1668846871 I believe this was PR feedback at the time. Happy to change it
src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.Split.cs
Outdated
Show resolved
Hide resolved
8c52bf2
to
dd98d20
Compare
Implements #934
TODO:
IEquatable<T>
type constraint is necessary due to the type constraint existing on theSystem.MemoryExtensions.IndexOf<T>()
overloads and onSearchValues<T>
.