Skip to content
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

Replace String.CompareOrdinal to string.Equals in KnownTypes #7500

Merged
merged 1 commit into from
Mar 20, 2023

Conversation

lindexi
Copy link
Member

@lindexi lindexi commented Feb 4, 2023

Description

We can use string.Equals(string1, string2, StringComparison.Ordinal) to check for equality, see https://learn.microsoft.com/en-us/dotnet/csharp/how-to/compare-strings and https://learn.microsoft.com/en-us/dotnet/standard/base-types/best-practices-strings

Use the String.Compare and String.CompareTo methods to sort strings, not to check for equality.

Reference #6588

Cc @Kuldeep-MS

Customer Impact

Small performance improvements

Regression

None.

Testing

Just CI.

Risk

Low.

Microsoft Reviewers: Open in CodeFlow

@lindexi lindexi requested a review from a team as a code owner February 4, 2023 11:54
@ghost ghost assigned lindexi Feb 4, 2023
@ghost ghost added the PR metadata: Label to tag PRs, to facilitate with triage label Feb 4, 2023
@ghost ghost requested review from dipeshmsft and singhashish-wpf February 4, 2023 11:54
@ghost ghost added the Community Contribution A label for all community Contributions label Feb 4, 2023
@dipeshmsft dipeshmsft self-assigned this Feb 5, 2023
@Symbai
Copy link
Contributor

Symbai commented Feb 5, 2023

Curious why this is limited to KnownTypes only? A quick search here on Github shows that string.Compare is being used in >36 files. Wouldn't it make sense changing them all at once, so you don't end up with mixed coding styles?

@lindexi
Copy link
Member Author

lindexi commented Feb 6, 2023

Thank you @Symbai

Please don't worry, I will continue to optimize the code. Small changes help code review, and changing too much code at once can lead to conflicts

@omariom
Copy link
Contributor

omariom commented Feb 12, 2023

For x86 string equality operator generates a bit more efficient code.

@dipeshmsft dipeshmsft merged commit c1481e2 into dotnet:main Mar 20, 2023
@lindexi
Copy link
Member Author

lindexi commented Mar 20, 2023

Thank you @dipeshmsft

And I will update the other files soon @Symbai

lindexi added a commit to dotnet-campus/wpf that referenced this pull request Mar 28, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Apr 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Community Contribution A label for all community Contributions PR metadata: Label to tag PRs, to facilitate with triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants