Skip to content

Reduce redundant lookup in OrderedDictionary<TKey, TValue>.Remove#128988

Open
prozolic wants to merge 1 commit into
dotnet:mainfrom
prozolic:ordereddictionary
Open

Reduce redundant lookup in OrderedDictionary<TKey, TValue>.Remove#128988
prozolic wants to merge 1 commit into
dotnet:mainfrom
prozolic:ordereddictionary

Conversation

@prozolic
Copy link
Copy Markdown
Contributor

@prozolic prozolic commented Jun 4, 2026

This PR reduces a redundant lookup in OrderedDictionary<TKey, TValue>.Remove(KeyValuePair<TKey, TValue>) by using the index obtained from TryGetValue to call RemoveAt.
I also removed a duplicated null check in IDictionary.Add.

Reduce a redundant lookup in
`OrderedDictionary<TKey, TValue>.Remove(KeyValuePair<TKey, TValue>)`
by using the index obtained from `TryGetValue` to call `RemoveAt`.
Also remove a duplicated null check in `IDictionary.Add`.
Copilot AI review requested due to automatic review settings June 4, 2026 14:58
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Jun 4, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates OrderedDictionary<TKey, TValue> to optimize removal via ICollection<KeyValuePair<TKey, TValue>> and adjusts IDictionary.Add(object, object?) value handling.

Changes:

  • Avoids a second lookup by removing via index (RemoveAt) when KeyValuePair key+value match.
  • Removes an ArgumentNullException guard when adding null via non-generic IDictionary.Add.

@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.

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.

2 participants