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.

This is a speculative change, I don't have performance numbers.  I will
watch the performance buildbots and if this change does not help, I'll
revert.

Swift SVN r27607
This commit is contained in:
Dmitri Hrybenko
2015-04-22 22:08:16 +00:00
parent d4e744b2ed
commit 21e5a83631
4 changed files with 44 additions and 18 deletions

View File

@@ -378,23 +378,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()
//===----------------------------------------------------------------------===//