[swift-corelibs-dev] Collection.map doesn't call `makeIterator()`
tvermeulen at me.com
Mon Sep 26 14:11:52 CDT 2016
The implementation of Collection.map can be found here: https://github.com/apple/swift/blob/master/stdlib/public/core/Collection.swift#L1265-L1286
It uses repeated subscripts, rather than `makeIterator()`. Isn’t this a problem? I overloaded `makeIterator` on a custom collection once (I think it was a binary tree) because an iterator would be able to iterate the collection more efficiently than subscripts would (both O(n), but with a lower constant factor). If `makeIterator` isn’t overloaded, then subscripts are used anyways (by `IndexingIterator`). Wouldn’t it make more sense to use an iterator in Collection.map instead, in order to benefit from a possibly more efficient iterator than the default one?
More information about the swift-corelibs-dev