mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
stdlib: make map() dynamically dispatched
This change tries to recover the performance regression in map() that was caused by moving map() to a protocol extension and degrading the static type information (when mapping a collection, we only know that it is a sequence). Adding map() to the witness table allows us to provide a specialized implementation for collections, and hopefully recover the lost performance. Swift SVN r28416
This commit is contained in:
@@ -388,23 +388,6 @@ extension SequenceType {
|
||||
}
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// map()
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
extension SequenceType {
|
||||
/// Return an `Array` containing the results of mapping `transform`
|
||||
/// over `self`.
|
||||
final public func _prext_map<T>(
|
||||
@noescape transform: (${GElement}) -> T
|
||||
) -> [T] {
|
||||
// Cast away @noescape.
|
||||
typealias Transform = (${GElement}) -> T
|
||||
let escapableTransform = unsafeBitCast(transform, Transform.self)
|
||||
return Array<T>(lazy(self).map(escapableTransform))
|
||||
}
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// flatMap()
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
Reference in New Issue
Block a user