Reduce redundant lookup in OrderedDictionary<TKey, TValue>.Remove#128988
Open
prozolic wants to merge 1 commit into
Open
Reduce redundant lookup in OrderedDictionary<TKey, TValue>.Remove#128988prozolic wants to merge 1 commit into
prozolic wants to merge 1 commit into
Conversation
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`.
Contributor
There was a problem hiding this comment.
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) whenKeyValuePairkey+value match. - Removes an
ArgumentNullExceptionguard when addingnullvia non-genericIDictionary.Add.
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-collections |
This was referenced Jun 4, 2026
Open
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR reduces a redundant lookup in
OrderedDictionary<TKey, TValue>.Remove(KeyValuePair<TKey, TValue>)by using the index obtained fromTryGetValueto callRemoveAt.I also removed a duplicated null check in
IDictionary.Add.