<div dir="ltr">Pull-request for the change here: <a href="https://github.com/apple/swift/pull/1544">https://github.com/apple/swift/pull/1544</a></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Mar 5, 2016 at 1:18 PM, Dmitri Gribenko via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Fri, Mar 4, 2016 at 5:51 PM, Dave Abrahams via swift-evolution<br>
<<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br>
><br>
> on Fri Mar 04 2016, Patrick Pijnappel <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br>
><br>
>>><br>
>>> What algorithms or components can be simplified by taking advantage of this<br>
>>> extra guarantee?<br>
>><br>
>> Any generator that somehow buffers their underlying generator (as it can't<br>
>> tell whether it already tried to refill the buffer). For example UTF8 &<br>
>> UTF16's decode() both have 3 instead of 2 branches on ASCII input because<br>
>> of this.<br>
>><br>
>>> Off the top of my head: a stream of random numbers that stops when it<br>
>>> encounters<br>
>>> a zero.<br>
>><br>
>> You could generate the next random number in advance (you take a O(1) hit<br>
>> instead of O(n)). Of course consuming more than you need is not always<br>
>> allowed and the O(1) could outweigh the branch.<br>
>><br>
>> Overall I'd say performance-wise both categories are small (though taking<br>
>> the standard library as sample case, we have some examples of the former<br>
>> but not the latter).<br>
>><br>
>> We'd be left with the safety concern of code which fails in rare corner<br>
>> cases.<br>
><br>
> Thanks, this is helpful. I'm leaning in favor of making the change.<br>
<br>
</span>After thinking about this more, in context of implementation<br>
experience, existing generators in the library, I'm also in favor of<br>
providing this guarantee.<br>
<div class="HOEnZb"><div class="h5"><br>
Dmitri<br>
<br>
--<br>
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if<br>
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <<a href="mailto:gribozavr@gmail.com">gribozavr@gmail.com</a>>*/<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</div></div></blockquote></div><br></div>