Skip to content

Fix incorrect docstring on List.EnsureCapacity - #95956

Merged
eiriktsarpalis merged 3 commits into
dotnet:mainfrom
Smaug123:patch-1
Dec 13, 2023
Merged

Fix incorrect docstring on List.EnsureCapacity#95956
eiriktsarpalis merged 3 commits into
dotnet:mainfrom
Smaug123:patch-1

Conversation

@Smaug123

@Smaug123 Smaug123 commented Dec 13, 2023

Copy link
Copy Markdown
Contributor

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 area-System.Collections community-contribution Indicates that the PR has been added by a community member labels Dec 13, 2023
@ghost

ghost commented Dec 13, 2023

Copy link
Copy Markdown

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: -

Comment thread src/libraries/System.Private.CoreLib/src/System/Collections/Generic/List.cs Outdated

@eiriktsarpalis eiriktsarpalis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@jkotas

jkotas commented Dec 13, 2023

Copy link
Copy Markdown
Member

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