Skip to content

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

Merged
dipeshmsft merged 1 commit into
dotnet:mainfrom
dotnet-campus:t/lindexi/KnownTypes
Mar 20, 2023
Merged

dipeshmsft merged 1 commit into
dotnet:mainfrom
dotnet-campus:t/lindexi/KnownTypes

Conversation

@lindexi

@lindexi lindexi commented Feb 4, 2023 •

Copy link
Copy Markdown
Member

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

Symbai commented Feb 5, 2023

Copy link
Copy Markdown
Contributor

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

lindexi commented Feb 6, 2023

Copy link
Copy Markdown
Member Author

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

omariom commented Feb 12, 2023

Copy link
Copy Markdown
Contributor

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

@dipeshmsft
dipeshmsft merged commit c1481e2 into dotnet:main Mar 20, 2023
@lindexi

lindexi commented Mar 20, 2023

Copy link
Copy Markdown
Member Author

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