File tree Expand file tree Collapse file tree 1 file changed +11
-11
lines changed Expand file tree Collapse file tree 1 file changed +11
-11
lines changed Original file line number Diff line number Diff line change @@ -1199,18 +1199,18 @@ extension Collection {
1199
1199
return [ ]
1200
1200
}
1201
1201
1202
- var result = ContiguousArray < T > ( )
1203
- result. reserveCapacity ( n)
1204
-
1205
- var i = self . startIndex
1206
-
1207
- for _ in 0 ..< n {
1208
- result. append ( try transform ( self [ i] ) )
1209
- formIndex ( after: & i)
1202
+ return try unsafe Array< T > ( unsafeUninitializedCapacity: n) { (
1203
+ storage: inout UnsafeMutableBufferPointer < T > ,
1204
+ initializedCount: inout Int
1205
+ ) throws ( E) - > Void in
1206
+ var collectionIndex = self . startIndex
1207
+ for bufferIndex in 0 ..< n {
1208
+ unsafe storage[ bufferIndex] = try transform ( self [ collectionIndex] )
1209
+ formIndex ( after: & collectionIndex)
1210
+ initializedCount += 1
1211
+ }
1212
+ _expectEnd( of: self , is: collectionIndex)
1210
1213
}
1211
-
1212
- _expectEnd ( of: self , is: i)
1213
- return Array ( result)
1214
1214
}
1215
1215
1216
1216
// ABI-only entrypoint for the rethrows version of map, which has been
You can’t perform that action at this time.
0 commit comments