This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Use vectorized SpanHelpers.SequenceEqual for string equality#16994
Merged
jkotas merged 1 commit intodotnet:masterfrom Mar 17, 2018
Merged
Use vectorized SpanHelpers.SequenceEqual for string equality#16994jkotas merged 1 commit intodotnet:masterfrom
jkotas merged 1 commit intodotnet:masterfrom
Conversation
Member
Author
|
Depends on dotnet/corefx#28080 that is changing SpanHelpers.SequenceEqual argument to nuint. |
Member
Author
|
cc @marek-safar |
ahsonkhan
reviewed
Mar 16, 2018
| return (value.Length == 1) ? | ||
| true : // First char is the same and thats all there is to compare | ||
| StartsWithOrdinalHelper(this, value); | ||
| SpanHelpers.SequenceEqual( |
There was a problem hiding this comment.
What happens if this.Length is less than value.Length?
Member
Author
There was a problem hiding this comment.
This condition is checked two lines above this one.
|
@jkotas very nice We are still using https://github.com/dotnet/corert/blob/master/src/System.Private.CoreLib/src/System/String.Comparison.cs but this file looks quite easy to unify/share |
Member
Author
|
@dotnet-bot test this please |
Member
Author
|
@dotnet-bot test Ubuntu x64 Checked corefx_baseline |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SpanHelpers.SequenceEqual is our optimized workhorse for comparing blocks of memory. Use it for string equality instead of ad-hoc optimized loops.
"Hello world!".Equals("Hello world?")is 20% faster on x64 with this change and it only gets better from there.