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

[SR-2909] Array should have an initializer that reserves capacity #45503

Closed
phausler opened this issue Oct 10, 2016 · 1 comment
Closed

[SR-2909] Array should have an initializer that reserves capacity #45503

phausler opened this issue Oct 10, 2016 · 1 comment
Assignees
Labels
feature A feature request or implementation improvement standard library Area: Standard library umbrella swift evolution implemented Flag → feature: A feature that was approved through the Swift evolution process and implemented

Comments

@phausler
Copy link
Member

Previous ID SR-2909
Radar None
Original Reporter @phausler
Type Improvement
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Improvement
Assignee @natecook1000
Priority Medium

md5: ebb4e496b3292639eda6001214f4d056

is duplicated by:

  • SR-3027 add Array.init(minimumCapacity: Int)

Issue Description:

When knowing an array will immediately be filled with a specific count of items it is often common to write:

var array = [Value]()
array.reserveCapacity(count)

it would be nice to have an initializer that reserves capacity (since it would be similar to other allocation paths of buffers)

var array = [Value](reservingCapacity: count)

trivially this could be written as:

extension Array {
    init(reservingCapacity count: Int) {
        self.init()
        self.reserveCapacity(count)
    }
}
@natecook1000
Copy link
Member

This has been approved and implemented as init(unsafeUninitializedCapacity:initializingWith:) for Swift 5.1.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added feature A feature request or implementation swift evolution implemented Flag → feature: A feature that was approved through the Swift evolution process and implemented labels Nov 11, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A feature request or implementation improvement standard library Area: Standard library umbrella swift evolution implemented Flag → feature: A feature that was approved through the Swift evolution process and implemented
Projects
None yet
Development

No branches or pull requests

3 participants