-
Notifications
You must be signed in to change notification settings - Fork 10.5k
🙅🏼♂️ [stdlib] Add method for accessing full storage capacity of array #17389
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
🙅🏼♂️ [stdlib] Add method for accessing full storage capacity of array #17389
Conversation
27e313f
to
365b5ec
Compare
@swift-ci Please smoke test |
Ugh — it looks like adding let problem = [1: 10, 2: 20].mapValues(String.init)
// old: [1: "10", 2: "20"]
// new: [1: "", 2: ""] |
@swift-ci Please smoke test |
stdlib/public/core/Array.swift
Outdated
inoutBufferPointer.count == capacity, | ||
""" | ||
Array withFullCapacityUnsafeMutableBufferPointer: \ | ||
replacing the buffer is not allowed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then why is it being passed inout
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like I'm cargo-culting the rationale for the buffer being inout
in withUnsafeMutableBufferPointer
, which is a very old behavior (introduced in c5c17e2). It looks like that was probably because the type used to access the elements then (UnsafeMutableArray
) needed to be mutable to access its subscript setter, unlike UnsafeMutableBufferPointer
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably prefer the correct semantics (non-inout
) over matching the existing method, esp. since you can't pass the same closure to both anyway. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh right, you do need mutation if you want to do collectiony things on the UnsafeMutableBufferPointer. But in this case it's not safe to do collectiony things unless you take a slice anyway, at which point you can use var
.
74bcc36
to
6292c4b
Compare
@swift-ci Please smoke test |
Closing until there's a new SE pitch. |
This is an implementation of a
withUnsafeMutableBufferPointerToStorage
method andinit(unsafeUninitializedCapacity:initializingWith:)
for arrays. Under review here: https://forums.swift.org/t/se-0223-accessing-an-arrays-uninitialized-buffer/15194To do:
@_semantics
attributes?ContiguousArray
Resolves #45677.