I have some question of map function on Collection
@_inlineable
public func map<T>(
_ transform: (Element) throws -> T
) rethrows -> [T] {
// TODO: swift-3-indexing-model - review the following
let n = self.count
if n == 0 {
return []
}
i see let n = self.count; if n == 0.
this shouldn’t be ‘if self.isEmpty { … }; let n = self.count’?
Look a few lines down and you’ll see that n is used as the capacity to reserve in a ContiguousArray. So it is correct as written: the count needs to be found and used.