Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Make randomized string equality comparers implement IAlternateEqualityComparer - #104252

#104252
Merged
stephentoub merged 2 commits into
dotnet:maindotnet/runtime:mainfrom
stephentoub:fixrandomcomparersstephentoub/runtime:fixrandomcomparersCopy head branch name to clipboard
Jul 2, 2024
Merged

Make randomized string equality comparers implement IAlternateEqualityComparer#104252
stephentoub merged 2 commits into
dotnet:maindotnet/runtime:mainfrom
stephentoub:fixrandomcomparersstephentoub/runtime:fixrandomcomparersCopy head branch name to clipboard

Conversation

@stephentoub

Copy link
Copy Markdown
Member

When Dictionary<string,TValue> and HashSet<string> upgrade from a non-randomized comparer to a randomized comparer, they don't just switch to using StringComparer.Xx... for an extra layer of protection, they create a dedicated comparer with its own random seed rather than sharing the global one. This is accomplished with a couple of dedicated comparer types. When I added IAlternateEqualityComparer implementations to all the things, I missed these two cases. That means when if a dictionary/hashset experienced enough collisions to upgrade, it could lose its ability to perform alternate key lookups. This PR just fixes those two stragglers.

(This will not pass CI until #104202 is merged, as the tests here expect that the default comparer supports alternates.)

@IDisposable IDisposable left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.