[swift-users] Need better name, want to hide generator
jnosh at jnosh.com
Sun Dec 20 10:07:03 CST 2015
Just a quick side note with regards to:
> Dmitri adds: "You can use AnySequence and AnyGenerator, but they come at a cost of dynamic dispatch for every call. In this case, if you want this component to be suitable for performance-critical code, I would suggest to avoid them for now."
This is very much true. But since Swift 2.0, that overhead can actually be avoided for AnyGenerator given enough context.
Basically, if the producer and consumer of the sequence are in the same module and with whole module optimization enabled (or putting all the relevant parts in the same file), AnyGenerator can be as fast as a native generator.
It's of limited usefulness and a bit weird to use AnyGenerator instead of AnySequence but it can be handy when:
* performance is critical,
* you want to use more than one sequence type (with different generators)
* and can't use generic functions to solve your problem...
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-users