[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:
Dave Abrahams
2014-07-28 01:03:09 +00:00
parent f650c85af2
commit 31d6f95452
15 changed files with 48 additions and 40 deletions

View File

@@ -321,7 +321,7 @@ NSStringAPIs.test("dataUsingEncoding(_:allowLossyConversion:)") {
let data = "あいう".dataUsingEncoding(NSUTF8StringEncoding)
let bytes = Array(
UnsafeBufferPointer(
start: UnsafePointer<UInt8>(data!.bytes), length: data!.length))
start: UnsafePointer<UInt8>(data!.bytes), count: data!.length))
let expectedBytes: [UInt8] = [
0xe3, 0x81, 0x82, 0xe3, 0x81, 0x84, 0xe3, 0x81, 0x86
]