Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stored the initial capacity of the ConcurrentDictionary for correctly sizing the backing array after clearing the collection. #108065

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

koenigst
Copy link
Contributor

  • Stored the capacity in the ctor.
  • Used the stored capacity in Clear().
  • No tests were added or changed as the capacity logic was only implicitly tested.

Fixes #107016

… sizing the backing array after clearing the collection.

* Stored the capacity in the ctor.
* Used the stored capacity in Clear().

Fixes dotnet#107016
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Sep 20, 2024
Copy link
Contributor

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

Copy link
Member

@eiriktsarpalis eiriktsarpalis left a comment

Choose a reason for hiding this comment

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

LGTM. @stephentoub any objections?

@eiriktsarpalis
Copy link
Member

  • No tests were added or changed as the capacity logic was only implicitly tested.

There is precedent in us using reflection to check intentional properties of collections types. Not sure if warranted here, but bare minimum you should try to check if there is test coverage for passing a large-ish capacity parameter and then clearing the collection.

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.

[API Proposal]: ConcurrentDictionary.Clear(bool noResize)
2 participants