Remove StringSpanHelpers and start using MemoryExtensions#16718
Remove StringSpanHelpers and start using MemoryExtensions#16718ahsonkhan merged 3 commits intodotnet:masterfrom
Conversation
|
@dotnet-bot test Windows_NT arm Cross Checked corefx_baseline Build and Test |
|
@dotnet-bot test OSX10.12 x64 Checked Innerloop Build and Test |
|
@dotnet-bot test OSX10.12 x64 Checked Innerloop Build and Test please |
2 similar comments
|
@dotnet-bot test OSX10.12 x64 Checked Innerloop Build and Test please |
|
@dotnet-bot test OSX10.12 x64 Checked Innerloop Build and Test please |
|
|
||
| // TODO https://github.com/dotnet/corefx/issues/21395: Expose this publicly? | ||
| internal virtual int Compare(ReadOnlySpan<char> string1, ReadOnlySpan<char> string2, CompareOptions options) | ||
| internal virtual int CompareOptionNone(ReadOnlySpan<char> string1, ReadOnlySpan<char> string2, CompareOptions options) |
There was a problem hiding this comment.
Why take take an options and force it to be None if it's not going to be used?
There was a problem hiding this comment.
We need to pass the option to CompareString which passes it to the interop call.
There was a problem hiding this comment.
Hmm... I just realized what you meant. Lol.
We can simply do the following:
internal virtual int CompareOptionNone(ReadOnlySpan<char> string1, ReadOnlySpan<char> string2)
{
return _invariantMode ?
string.CompareOrdinal(string1, string2) :
CompareString(string1, string2, CompareOptions.None);
}| return CompareString(string1, string2, options); | ||
| internal virtual int CompareOptionIgnoreCase(ReadOnlySpan<char> string1, ReadOnlySpan<char> string2, CompareOptions options) | ||
| { | ||
| Debug.Assert(options == CompareOptions.IgnoreCase); |
There was a problem hiding this comment.
Same question for IgnoreCase... why aren't all of these just calling CompareString?
There was a problem hiding this comment.
Should I make private unsafe int CompareString(ReadOnlySpan<char> string1, ReadOnlySpan<char> string2, CompareOptions options) internal and call it directly?
|
Trying MSIT fix |
src/mscorlib/shared/System/Guid.cs
Outdated
| // Find the end of this hex number (since it is not fixed length) | ||
| numStart = 3; | ||
| numLen = guidString.IndexOf(',', numStart) - numStart; | ||
| numLen = guidString.Slice(numStart).IndexOf(',') - numStart; |
There was a problem hiding this comment.
Have you runs our tests, and does this pass? Putting in the slice will change the resulting value as compared to passing in a start index.
There was a problem hiding this comment.
Same comment for all of these.
There was a problem hiding this comment.
I ran the corefx System.Runtime tests locally. I didn't run the coreclr tests.
I will fix the bug and run the coreclr tests.
There was a problem hiding this comment.
I actually meant the corefx tests. If we don't have a test that catches this, we should. This is wrong, right? Consider if numStart is 3 and the ',' is found at 4. Previously IndexOf(',',numStart) would return 4, and then we'd subtract 3 to get 1. Now IndexOf(',') will return 1, and then we'll subtract 3 to get -2.
There was a problem hiding this comment.
Yes, it is incorrect. We need to remove the - numStart
There was a problem hiding this comment.
We have these tests that, theoretically, should call into TryParseGuidWithHexPrefix. I will re-run the tests locally to see if they fail.
There was a problem hiding this comment.
Yep, the tests catch this bug and do fail. I must not have re-built coreclr successfully with my changes earlier (probably due to the issue with HW_Flag_BaseTypeFromFirstArg).
| Span<char> result = new char[i + 1]; | ||
| result[i] = ch; | ||
| Value.Slice(0, i).CopyTo(result); | ||
| Value = result.AsReadOnlySpan(); |
There was a problem hiding this comment.
Do we have any tests that hit this and the below removal paths? It'd be good to make sure they're covered.
There was a problem hiding this comment.
I will check and add if needed.
There was a problem hiding this comment.
Added some tests for this particular codepath - dotnet/corefx#27678
Filed an issue for the rest: https://github.com/dotnet/corefx/issues/27679
| // We musn't have any separators after build. | ||
| int buildEnd = -1; | ||
| int minorEnd = input.IndexOf('.', majorEnd + 1); | ||
| int minorEnd = input.Slice(majorEnd + 1).IndexOf('.'); |
There was a problem hiding this comment.
As with the other cases where slicing was added, I don't think this and the below cases do the right thing.
|
|
||
| public bool StartsWith(char value) => Length != 0 && _firstChar == value; | ||
|
|
||
| public static void CheckStringComparison(StringComparison comparisonType) |
| // Single comparison to check if comparisonType is within [CurrentCulture .. OrdinalIgnoreCase] | ||
| if ((uint)(comparisonType - StringComparison.CurrentCulture) > (StringComparison.OrdinalIgnoreCase - StringComparison.CurrentCulture)) | ||
| { | ||
| throw new ArgumentException(SR.NotSupported_StringComparison, nameof(comparisonType)); |
There was a problem hiding this comment.
Should this use ThrowHelper?
There was a problem hiding this comment.
We don't use ThrowHelper anywhere in this file. In what scenario would it help?
There was a problem hiding this comment.
ThrowHelper outside generics (where its codegen size); it helps with inlining and the size when inlined.
So
((uint)(comparisonType - StringComparison.CurrentCulture) > (StringComparison.OrdinalIgnoreCase - StringComparison.CurrentCulture))will probably easily inline
but add new, throw, nameof, SR.NotSupported_StringComparison and it probably won't
Whereas ThrowHelper.ThrowArgumentException(ExceptionResource.NotSupported_StringComparison) is one int constant register load and a call with no post cleanup (as it only throws).
There was a problem hiding this comment.
Gotcha. So, it will help inline CheckStringComparison, mainly for when it won't end up throwing (which is the most common scenario).
|
@dotnet-bot test OSX10.12 x64 Checked Innerloop Build and Test please |
1 similar comment
|
@dotnet-bot test OSX10.12 x64 Checked Innerloop Build and Test please |
|
OSX - https://github.com/dotnet/core-eng/issues/2808
Any other feedback before this gets merged? |
|
@dotnet-bot test OSX10.12 x64 Checked Innerloop Build and Test |
cc @stephentoub, @jkotas, @tarekgh, @benaadams
Ignore the change to src/jit/hwintrinsiclistxarch.h (it's from #16715)