<div dir="ltr"><div>Just FYI</div><div><br></div><div>Implementation of Type Erasers<br></div><a href="https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20160905/002852.html">https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20160905/002852.html</a><br><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-04-05 22:22 GMT+09:00 Pavol Vaskovic via swift-dev <span dir="ltr"><<a href="mailto:swift-dev@swift.org" target="_blank">swift-dev@swift.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Wednesday, 5 April 2017 at 14:56, Pavol Vaskovic wrote:<br>
> Thanks Ole! This explanation of type erasure makes total sense. I have overlooked they are generic over different axis.<br>
><br>
> But I think I have confirmed the performance implications of this design and created <a href="https://bugs.swift.org/browse/SR-4499" rel="noreferrer" target="_blank">https://bugs.swift.org/browse/<wbr>SR-4499</a> to track the issue.<br>
> As is, all elements that get vended through this are being created using virtual dispatch on generic protocol - super slow.<br>
><br>
> If I recall correctly, there is alternative approach to type erasure using closures, but its possible it has similar performance characteristics?<br>
</span>Why exactly isn’t `AnyIterator` implemented like this?<br>
<br>
public struct AnyIterator<Element> : IteratorProtocol, Sequence {<br>
let _next: () -> Element?<br>
public init<I : IteratorProtocol>(_ base: I) where I.Element == Element {<br>
var _base = base<br>
_next = { return _base.next() }<br>
}<br>
public init(_ next: @escaping () -> Element?) {<br>
_next = next<br>
}<br>
public func next() -> Element? {<br>
return _next()<br>
}<br>
}<br>
<br>
<br>
It seems to me this is using the same "Methods Constructed in Initializers” pattern I was asking about Re: `_ClosureBasedIterator`.<br>
<div class="HOEnZb"><div class="h5"><br>
Best regards<br>
Pavol Vaskovic<br>
<br>
<br>
<br>
______________________________<wbr>_________________<br>
swift-dev mailing list<br>
<a href="mailto:swift-dev@swift.org">swift-dev@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-dev" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-dev</a><br>
</div></div></blockquote></div><br></div>