[swift-dev] Implementation of Existential Collection (AnySequence and co.)
rintaro ishizaki
fs.output at gmail.com
Wed Apr 5 09:04:18 CDT 2017
Just FYI
Implementation of Type Erasers
https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20160905/002852.html
2017-04-05 22:22 GMT+09:00 Pavol Vaskovic via swift-dev <swift-dev at swift.org
>:
> On Wednesday, 5 April 2017 at 14:56, Pavol Vaskovic wrote:
> > Thanks Ole! This explanation of type erasure makes total sense. I have
> overlooked they are generic over different axis.
> >
> > But I think I have confirmed the performance implications of this design
> and created https://bugs.swift.org/browse/SR-4499 to track the issue.
> > As is, all elements that get vended through this are being created using
> virtual dispatch on generic protocol - super slow.
> >
> > If I recall correctly, there is alternative approach to type erasure
> using closures, but its possible it has similar performance characteristics?
> Why exactly isn’t `AnyIterator` implemented like this?
>
> public struct AnyIterator<Element> : IteratorProtocol, Sequence {
> let _next: () -> Element?
> public init<I : IteratorProtocol>(_ base: I) where I.Element == Element {
> var _base = base
> _next = { return _base.next() }
> }
> public init(_ next: @escaping () -> Element?) {
> _next = next
> }
> public func next() -> Element? {
> return _next()
> }
> }
>
>
> It seems to me this is using the same "Methods Constructed in
> Initializers” pattern I was asking about Re: `_ClosureBasedIterator`.
>
> Best regards
> Pavol Vaskovic
>
>
>
> _______________________________________________
> swift-dev mailing list
> swift-dev at swift.org
> https://lists.swift.org/mailman/listinfo/swift-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20170405/e70071ab/attachment.html>
More information about the swift-dev
mailing list