You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Proposal: Add ReadOnlySpan<char> overloads to CompareInfo #25428
While doing some Span optimizations in Regex I noticed that the current comparison extension methods on ROS don't support comparison with a specific culture: MemoryExtensions.CompareTo(this ReadOnlySpan<char> span, ReadOnlySpan<char> value, StringComparison comparisonType).
With string I can do that in different ways either by string.Compare(string, string, CultureInfo, CompareOptions); or by StringComparer.Create(CultureInfo, bool ignoreCase).Compare(string, string).
by the way, I believe we didn't expose any span API that takes CompareOptions either. If we are going to expose API takes culture, then we have to use CompareOptions that time.
I don't think there was any specific reason to not expose this one.
The current situation isn't ideal as I don't see a way to compare two strings with a specific culture and CompareOptions. In my case I need to allocate the string from the Span to do the comparison.
you cannot use the string for this comparison or your code is already using spans?
Correct, I'm switching to Span to reduce allocation.
by the way, I believe we didn't expose any span API that takes CompareOptions either. If we are going to expose API takes culture, then we have to use CompareOptions that time.
@ahsonkhan do you know any other workaround from the span side?
@ViktorHofer do you have the original strings that you constructed the span from in the first place? if so, I believe you can use these strings without the allocation. otherwise, I would say just file API request issue but I am not sure if we still open to introduce more new APIs in 2.1.
What about the other APIs like Start/EndsWith? Consider adding those to the proposal as well.
@tarekgh should we also add these? I see that these only have bool ignoreCase, CultureInfo culture overloads on string. Should we mimic them or can we also make use of CompareOptions here?
should we also add these? I see that these only have bool ignoreCase, CultureInfo culture overloads on string. Should we mimic them or can we also make use of CompareOptions here?
System.Memory is not a nuget package anymore. It was folded into runtime (aka inboxed). It cannot evolve.
Also, adding this to System.Memory would mean using extension methods for this that is not the natural shape for these APIs and does not follow API design guidelines.
Approved over email. Feedback was to rename the destination parameter of GetSortKey to destination instead of sortKey. I've updated the proposal to reflect this.
ghost locked as resolved and limited conversation to collaborators on Dec 17, 2020
Activity
tarekgh commentedon Mar 13, 2018
I don't think there was any specific reason to not expose this one. you cannot use the string for this comparison or your code is already using spans?
tarekgh commentedon Mar 13, 2018
by the way, I believe we didn't expose any span API that takes CompareOptions either. If we are going to expose API takes culture, then we have to use CompareOptions that time.
ViktorHofer commentedon Mar 13, 2018
The current situation isn't ideal as I don't see a way to compare two strings with a specific culture and CompareOptions. In my case I need to allocate the string from the Span to do the comparison.
Correct, I'm switching to Span to reduce allocation.
Agreed.
tarekgh commentedon Mar 13, 2018
@ahsonkhan do you know any other workaround from the span side?
@ViktorHofer do you have the original strings that you constructed the span from in the first place? if so, I believe you can use these strings without the allocation. otherwise, I would say just file API request issue but I am not sure if we still open to introduce more new APIs in 2.1.
ViktorHofer commentedon Mar 13, 2018
Not really in this layer where I'm operating. I will file an issue as I believe others will hit that also.
[-]ROS comparison with specific culture[/-][+]Proposal: Add support for ROS comparison with specified culture[/+]ViktorHofer commentedon Mar 13, 2018
Reused this item for the proposal.
ahsonkhan commentedon Mar 13, 2018
Should we also consider providing the other overloads on string like the ones that take bool and CultureInfo without CompareOptions:
What about the other APIs like Start/EndsWith? Consider adding those to the proposal as well.
There isn't really a workaround for this that doesn't end up re-allocating the string.
ViktorHofer commentedon Mar 13, 2018
I believe just using bool ignoreCase is legacy and not needed if you have a CompareOptions enum. @tarekgh can correct me here.
tarekgh commentedon Mar 13, 2018
I don't think we need the APIs takes the bool ignore cases. but we may need to have IndexOf/LastIndexOf overloads that take culture and CompareOptions
ViktorHofer commentedon Mar 14, 2018
We currently don't have such for string. So this will be entirely new APIs?
tarekgh commentedon Mar 14, 2018
We have these exposed from CompareInfo class.
ViktorHofer commentedon Mar 14, 2018
@tarekgh should we also add these? I see that these only have
bool ignoreCase, CultureInfo cultureoverloads on string. Should we mimic them or can we also make use of CompareOptions here?tarekgh commentedon Mar 14, 2018
The apis should look like:
The other option is to add these extension methods to CompareInfo (instead of the Span) and at that time we'll not pass CultureInfo.
I prefer the CompareInfo option because this will be consistent with the strings APIs.
tarekgh commentedon Mar 14, 2018
Also, I prefer to expose the proposed CompareTo from CompareInfo too with the name "Compare"
39 remaining items
tarekgh commentedon Jan 31, 2020
@jskeet So far this is marked for netcoreapp 5.0 and not netstandard 2.0. Unfortunately, the only workaround for this has to allocate strings.
@terrajobst is there a way we can add these new APIs to netsatndard 2.0?
jkotas commentedon Jan 31, 2020
No. .NET Standard 2.0 is set in stone.
jskeet commentedon Jan 31, 2020
It can't be added to .NET Standard 2.0... but it could be added to the System.Memory nuget package. That's what I was hoping for :)
jkotas commentedon Jan 31, 2020
System.Memory is not a nuget package anymore. It was folded into runtime (aka inboxed). It cannot evolve.
Also, adding this to System.Memory would mean using extension methods for this that is not the natural shape for these APIs and does not follow API design guidelines.
GrabYourPitchforks commentedon Apr 15, 2020
Missed a few overloads on
CompareInfoearlier:Marked as blocking because it's blocking PR #1514.
Related: #27912
GrabYourPitchforks commentedon Apr 24, 2020
Approved over email. Feedback was to rename the destination parameter of
GetSortKeyto destination instead of sortKey. I've updated the proposal to reflect this.