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

Cleanup rest of string.Compare[Ordinal] equality checks and replace it with string.Equals #9740

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

h3xds1nz
Copy link
Contributor

@h3xds1nz h3xds1nz commented Sep 8, 2024

Description

Finishes up all the easily replaceable string.Compare method uses that are used strictly for equality. The only leftovers shall be now covered in my other PRs where I don't wanna create conflicts for each one of them.

Difference in the last character

Method Mean [ns] Error [ns] StdDev [ns] Code Size [B] Allocated [B]
Original 36.525 ns 0.7577 ns 0.7781 ns 446 B -
PR_EDIT 4.873 ns 0.0175 ns 0.0155 ns 467 B -

Difference in 5th character

Method Mean [ns] Error [ns] StdDev [ns] Code Size [B] Allocated [B]
Original 4.627 ns 0.0493 ns 0.0437 ns 446 B -
PR_EDIT 2.668 ns 0.0138 ns 0.0129 ns 467 B -

Benchmark source strings

//First invocation (last char is different)
return string.Compare("someveryrandomstringthatwillonlydifferintheveryendwewillmakesureofit0",
"someveryrandomstringthatwillonlydifferintheveryendwewillmakesureofit1", 
StringComparison.OrdinalIgnoreCase) == 0;
return string.Equals("someveryrandomstringthatwillonlydifferintheveryendwewillmakesureofit0",
"someveryrandomstringthatwillonlydifferintheveryendwewillmakesureofit1", 
StringComparison.OrdinalIgnoreCase);

//Second invocation (5th char is different)
return string.Compare("some0veryrandomstringthatwillonlydifferintheveryendwewillmakesureofit0",
"some1veryrandomstringthatwillonlydifferintheveryendwewillmakesureofit1", 
StringComparison.OrdinalIgnoreCase) == 0;
return string.Equals("some0veryrandomstringthatwillonlydifferintheveryendwewillmakesureofit0",
"some1veryrandomstringthatwillonlydifferintheveryendwewillmakesureofit1", 
StringComparison.OrdinalIgnoreCase);

Customer Impact

Improved performance.

Regression

No.

Testing

Local build.

Risk

Very low, those are IDE swaps besides three manual edits.

Microsoft Reviewers: Open in CodeFlow

@h3xds1nz h3xds1nz requested review from a team as code owners September 8, 2024 00:05
@dotnet-policy-service dotnet-policy-service bot added PR metadata: Label to tag PRs, to facilitate with triage Community Contribution A label for all community Contributions labels Sep 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.

1 participant