Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions stdlib/public/core/Collection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1199,18 +1199,18 @@ extension Collection {
return []
}

var result = ContiguousArray<T>()
result.reserveCapacity(n)

var i = self.startIndex

for _ in 0..<n {
result.append(try transform(self[i]))
formIndex(after: &i)
}

_expectEnd(of: self, is: i)
return Array(result)
return try unsafe Array(ContiguousArray<T>(unsafeUninitializedCapacity: n) { (
storage: inout UnsafeMutableBufferPointer<T>,
initializedCount: inout Int
) throws(E) -> Void in
var collectionIndex = self.startIndex
for bufferIndex in storage.indices {
unsafe storage.initializeElement(at: bufferIndex, to: try transform(self[collectionIndex]))
formIndex(after: &collectionIndex)
initializedCount += 1
}
_expectEnd(of: self, is: collectionIndex)
})
}

// ABI-only entrypoint for the rethrows version of map, which has been
Expand Down