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:
Dmitri Hrybenko
2015-05-11 15:59:02 +00:00
parent c2ff0f8f9a
commit 7ac7eba882
4 changed files with 228 additions and 25 deletions

View File

@@ -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()
//===----------------------------------------------------------------------===//