Skip to content

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

Merged
eiriktsarpalis merged 1 commit into
dotnet:mainfrom
prozolic:ordereddictionary
Jun 5, 2026
Merged

Reduce redundant lookup in OrderedDictionary<TKey, TValue>.Remove#128988
eiriktsarpalis merged 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.

@eiriktsarpalis eiriktsarpalis enabled auto-merge (squash) June 5, 2026 12:59
@eiriktsarpalis
Copy link
Copy Markdown
Member

/ba-g test failures are unrelated

@eiriktsarpalis eiriktsarpalis merged commit a8b2c92 into dotnet:main Jun 5, 2026
102 of 105 checks passed
@prozolic prozolic deleted the ordereddictionary branch June 5, 2026 13:13
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview6 milestone Jun 6, 2026
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