-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Fix incorrect case sensitivity in FrozenDictionary and FrozenSet for some cases #93986
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
Closed
andrewjsaid
wants to merge
6
commits into
dotnet:main
from
andrewjsaid:frozen-collections-ordinal-ignore-case
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9a42c3e
Add failing tests
andrewjsaid a94513c
Fix incorrect case sensitivity in FrozenDictionary and FrozenSet for …
andrewjsaid 328d9f1
When hashing the entire string, case sensitivity of hash and equals s…
andrewjsaid 9d982d6
Merge branch 'main' into frozen-collections-ordinal-ignore-case
andrewjsaid 2f2a018
Address code review comments
andrewjsaid fdbb96a
Merge branch 'main' into frozen-collections-ordinal-ignore-case
andrewjsaid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -181,45 +181,67 @@ private static FrozenDictionary<TKey, TValue> CreateFromDictionary<TKey, TValue> | |
{ | ||
if (analysis.RightJustifiedSubstring) | ||
{ | ||
if (analysis.IgnoreCase) | ||
if (analysis.IgnoreCaseForHash) | ||
{ | ||
frozenDictionary = analysis.AllAsciiIfIgnoreCase | ||
Debug.Assert(analysis.IgnoreCase); | ||
frozenDictionary = analysis.AllAsciiIfIgnoreCaseForHash | ||
? new OrdinalStringFrozenDictionary_RightJustifiedCaseInsensitiveAsciiSubstring<TValue>(keys, values, stringComparer, analysis.MinimumLength, analysis.MaximumLengthDiff, analysis.HashIndex, analysis.HashCount) | ||
: new OrdinalStringFrozenDictionary_RightJustifiedCaseInsensitiveSubstring<TValue>(keys, values, stringComparer, analysis.MinimumLength, analysis.MaximumLengthDiff, analysis.HashIndex, analysis.HashCount); | ||
} | ||
else | ||
{ | ||
frozenDictionary = analysis.HashCount == 1 | ||
? new OrdinalStringFrozenDictionary_RightJustifiedSingleChar<TValue>(keys, values, stringComparer, analysis.MinimumLength, analysis.MaximumLengthDiff, analysis.HashIndex) | ||
: new OrdinalStringFrozenDictionary_RightJustifiedSubstring<TValue>(keys, values, stringComparer, analysis.MinimumLength, analysis.MaximumLengthDiff, analysis.HashIndex, analysis.HashCount); | ||
if (analysis.HashCount == 1) | ||
{ | ||
frozenDictionary = analysis.IgnoreCase | ||
? new OrdinalStringFrozenDictionary_RightJustifiedSingleCharCaseInsensitive<TValue>(keys, values, stringComparer, analysis.MinimumLength, analysis.MaximumLengthDiff, analysis.HashIndex) | ||
: new OrdinalStringFrozenDictionary_RightJustifiedSingleChar<TValue>(keys, values, stringComparer, analysis.MinimumLength, analysis.MaximumLengthDiff, analysis.HashIndex); | ||
} | ||
else | ||
{ | ||
frozenDictionary = analysis.IgnoreCase | ||
? new OrdinalStringFrozenDictionary_RightJustifiedSubstringCaseInsensitive<TValue>(keys, values, stringComparer, analysis.MinimumLength, analysis.MaximumLengthDiff, analysis.HashIndex, analysis.HashCount) | ||
: new OrdinalStringFrozenDictionary_RightJustifiedSubstring<TValue>(keys, values, stringComparer, analysis.MinimumLength, analysis.MaximumLengthDiff, analysis.HashIndex, analysis.HashCount); | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
if (analysis.IgnoreCase) | ||
if (analysis.IgnoreCaseForHash) | ||
{ | ||
frozenDictionary = analysis.AllAsciiIfIgnoreCase | ||
Debug.Assert(analysis.IgnoreCase); | ||
frozenDictionary = analysis.AllAsciiIfIgnoreCaseForHash | ||
? new OrdinalStringFrozenDictionary_LeftJustifiedCaseInsensitiveAsciiSubstring<TValue>(keys, values, stringComparer, analysis.MinimumLength, analysis.MaximumLengthDiff, analysis.HashIndex, analysis.HashCount) | ||
: new OrdinalStringFrozenDictionary_LeftJustifiedCaseInsensitiveSubstring<TValue>(keys, values, stringComparer, analysis.MinimumLength, analysis.MaximumLengthDiff, analysis.HashIndex, analysis.HashCount); | ||
} | ||
else | ||
{ | ||
frozenDictionary = analysis.HashCount == 1 | ||
? new OrdinalStringFrozenDictionary_LeftJustifiedSingleChar<TValue>(keys, values, stringComparer, analysis.MinimumLength, analysis.MaximumLengthDiff, analysis.HashIndex) | ||
: new OrdinalStringFrozenDictionary_LeftJustifiedSubstring<TValue>(keys, values, stringComparer, analysis.MinimumLength, analysis.MaximumLengthDiff, analysis.HashIndex, analysis.HashCount); | ||
if (analysis.HashCount == 1) | ||
{ | ||
frozenDictionary = analysis.IgnoreCase | ||
? new OrdinalStringFrozenDictionary_LeftJustifiedSingleCharCaseInsensitive<TValue>(keys, values, stringComparer, analysis.MinimumLength, analysis.MaximumLengthDiff, analysis.HashIndex) | ||
: new OrdinalStringFrozenDictionary_LeftJustifiedSingleChar<TValue>(keys, values, stringComparer, analysis.MinimumLength, analysis.MaximumLengthDiff, analysis.HashIndex); | ||
} | ||
else | ||
{ | ||
frozenDictionary = analysis.IgnoreCase | ||
? new OrdinalStringFrozenDictionary_LeftJustifiedSubstringCaseInsensitive<TValue>(keys, values, stringComparer, analysis.MinimumLength, analysis.MaximumLengthDiff, analysis.HashIndex, analysis.HashCount) | ||
: new OrdinalStringFrozenDictionary_LeftJustifiedSubstring<TValue>(keys, values, stringComparer, analysis.MinimumLength, analysis.MaximumLengthDiff, analysis.HashIndex, analysis.HashCount); | ||
} | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
if (analysis.IgnoreCase) | ||
if (analysis.IgnoreCaseForHash) | ||
{ | ||
frozenDictionary = analysis.AllAsciiIfIgnoreCase | ||
Debug.Assert(analysis.IgnoreCase); | ||
frozenDictionary = analysis.AllAsciiIfIgnoreCaseForHash | ||
? new OrdinalStringFrozenDictionary_FullCaseInsensitiveAscii<TValue>(keys, values, stringComparer, analysis.MinimumLength, analysis.MaximumLengthDiff) | ||
: new OrdinalStringFrozenDictionary_FullCaseInsensitive<TValue>(keys, values, stringComparer, analysis.MinimumLength, analysis.MaximumLengthDiff); | ||
} | ||
else | ||
{ | ||
// if (IgnoreCase) => Can only be true if there are no letters, thus case sensitive comparison still works here. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there an assertion that could replace this comment? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so because the assertion would just be re-calculating what the |
||
frozenDictionary = new OrdinalStringFrozenDictionary_Full<TValue>(keys, values, stringComparer, analysis.MinimumLength, analysis.MaximumLengthDiff); | ||
} | ||
} | ||
|
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.