-
Couldn't load subscription status.
- Fork 833
Use ordinal string comparison in string manipulation methods #4912
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
Use ordinal string comparison in string manipulation methods #4912
Conversation
0d334fc to
3b277e6
Compare
StartsWith, EndsWith, Compare, etc
3b277e6 to
568acd3
Compare
|
@dotnet-bot test Windows_NT Release_fcs Build please |
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 requesting a change to use StartsWithOrdinal etc. extension methods, thanks :)
src/absil/illib.fs
Outdated
| yield !line | ||
| line := reader.ReadLine() | ||
| if str.EndsWith("\n") then | ||
| if str.EndsWith("\n", StringComparison.Ordinal) then |
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.
Could you add StartsWithOrdinal/EndsWithOrdinal extension methods to illib.fs? Then it's easy to search and remove uses of StartsWith
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.
Done.
src/fsharp/CompileOps.fs
Outdated
| if r.Name.StartsWith(FSharpOptimizationDataResourceName, StringComparison.Ordinal) then | ||
| String.dropPrefix r.Name FSharpOptimizationDataResourceName | ||
| elif r.Name.StartsWith FSharpOptimizationDataResourceName2 then | ||
| elif r.Name.StartsWith(FSharpOptimizationDataResourceName2, StringComparison.Ordinal) then |
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 don't really know what comparison resource and assembly names should use. My understanding is that it doesn't actually make a difference if the thing being compared with is ASCII
|
assembly names are case insensitive, however guidance is that they should be treated as though they were case sensitive. (Which is pretty scary to me.) So StringComparison.Ordinal conforms to best practice for assembly names. https://docs.microsoft.com/en-us/dotnet/framework/app-domains/assembly-names ResourceManager is configurable: if ignore case is false, then does Culture sensitiveComparison, if ignore case is true does InvariantCulture lookup. |
|
If the guidance in that page for resources is correct, then Culture Sensitive is the way to go for perf and working set. |
9d1a26b to
21567ce
Compare
21567ce to
c751112
Compare
|
What I mean is, if the look up is going to be CultureSensitive in the resource manager, which it is, I don't think we set ignoreCase. I don't know whether A StringComparison.Ordinal check elsewhere can introduce bugs, my intuition is that it won't … but I truly don't know. |
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.
looks good.
|
@dotnet-bot test Windows_NT Release_ci_part2 Build please. |
|
@KevinRansom I think you meant CultureInsensitive? Because that's the only way resources are read the same way on all systems. And i think that's what the guidance you referenced suggests there. Changing that default may lead to builds failing on one system and succeeding on another (for instance, my build servers are in Germany and I develop in The Netherlands, I use resources a lot, marking the default Sensitive would possibly introduce hard to diagnose errors) |
Use overloads with StringComparison parameter where CurrentCulture would be used instead.