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

Fix incorrect docstring on List.EnsureCapacity #95956

Merged
merged 3 commits into from
Dec 13, 2023

Conversation

Smaug123
Copy link
Contributor

@Smaug123 Smaug123 commented Dec 13, 2023

The current docstring is false. The new capacity is computed as "twice the current capacity, and if that's still not enough, the user-specified capacity", as demonstrated in net8.0.100:

> open System;;
> let arr = ResizeArray<int> 3;;
val arr: ResizeArray<int>

> arr.Capacity;;
val it: int = 3

> arr.EnsureCapacity 9;;
val it: int = 9

> arr.Capacity;;
val it: int = 9

> arr.EnsureCapacity 11;;
val it: int = 18

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Dec 13, 2023
@ghost
Copy link

ghost commented Dec 13, 2023

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

Issue Details

The current docstring is false. The new capacity is computed as "twice the current capacity, and if that's still not enough, the user-specified capacity", as demonstrated in net8.0.100:

> open System;;
> let arr = ResizeArray<int>();;
val arr: ResizeArray<int>

> arr.Capacity;;
val it: int = 0

> arr.EnsureCapacity 9;;
val it: int = 9

> arr.Capacity;;
val it: int = 9
Author: Smaug123
Assignees: -
Labels:

area-System.Collections, community-contribution

Milestone: -

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.

Thanks!

@eiriktsarpalis eiriktsarpalis merged commit 4b91f91 into dotnet:main Dec 13, 2023
173 of 178 checks passed
@Smaug123 Smaug123 deleted the patch-1 branch December 13, 2023 14:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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