mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[stdlib] UnsafeBufferPointer: add ".count"
In answering a forum post I noiced that I wanted this and it was missing. Also, extensive comments Also, rename the length: init parameter to count:. When writing the comments for the init function it became painfully clear why we use "count" is better than "length" especially around pointers and memory: the former is much less easy to mistake for "length in bytes". Plus it's consistent with the new ".count" property Swift SVN r20609
This commit is contained in:
@@ -426,7 +426,7 @@ extension ${Self} {
|
||||
|
||||
// Create an UnsafeBufferPointer over work that we can pass to body
|
||||
var a = UnsafeMutableBufferPointer(
|
||||
start: work._buffer.baseAddress, length: work.count)
|
||||
start: work._buffer.baseAddress, count: work.count)
|
||||
|
||||
// Invoke the body
|
||||
let ret = body(&a)
|
||||
@@ -448,7 +448,7 @@ extension Array {
|
||||
) -> Array {
|
||||
let elements = UnsafeBufferPointer(
|
||||
start: unsafeBitCast(base, UnsafeMutablePointer<T>.self),
|
||||
length: unsafeBitCast(count, Int.self)
|
||||
count: unsafeBitCast(count, Int.self)
|
||||
)
|
||||
let r = Array(elements)
|
||||
_fixLifetime(owner)
|
||||
|
||||
Reference in New Issue
Block a user