Skip to content

Cleanup null check in Generic.SortedDictionary#126186

Closed
rustamque wants to merge 1 commit intodotnet:mainfrom
rustamque:fix-sorteddictionary-null-checks
Closed

Cleanup null check in Generic.SortedDictionary#126186
rustamque wants to merge 1 commit intodotnet:mainfrom
rustamque:fix-sorteddictionary-null-checks

Conversation

@rustamque
Copy link
Copy Markdown
Contributor

Contains method: Removed the redundant if (keyValuePair.Value == null) branch. EqualityComparer<TValue>.Default.Equals safely and optimally handles both reference and value types, resolving the warning without behavior changes.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Mar 27, 2026
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-collections
See info in area-owners.md if you want to be subscribed.

{
return EqualityComparer<TValue>.Default.Equals(node.Item.Value, keyValuePair.Value);
}
return EqualityComparer<TValue>.Default.Equals(node.Item.Value, keyValuePair.Value);
Copy link
Copy Markdown
Member

@EgorBo EgorBo Mar 27, 2026

Choose a reason for hiding this comment

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

NOTE: this is a perf regression when value is null as now we end up calling EqualityComparer<TValue>.Default.Equals with a slow runtime lookup and it's not inlined (even with PGO) for reference typed TValue.

@stephentoub
Copy link
Copy Markdown
Member

Thanks for the contribution. Closing per @EgorBo's comment that this is by design and will regress perf in some situations.

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

Labels

area-System.Collections community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants