<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 7 Jul 2016, at 02:06, Dmitri Gribenko <<a href="mailto:gribozavr@gmail.com" class="">gribozavr@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">On Wed, Jul 6, 2016 at 4:21 AM, Karl <<a href="mailto:razielim@gmail.com" class="">razielim@gmail.com</a>> wrote:<br class=""><blockquote type="cite" class="">I had a PR open for this which added a Collection specialisation, but you<br class="">said this could be handled in a more general way which allows for more<br class="">optimised mutations. I’m curious how this would work; how does<br class="">`RangeReplaceableCollection.replaceSubrange<S:Sequence>(range:, with: S)`<br class="">call a more optimised implementation if S also conforms to Collection, if<br class="">not by adding a specialisation?<br class=""></blockquote><br class="">The RRC can call into S.someCustomizationPoint(), which will<br class="">initialize a region of memory in the most efficient way possible,<br class="">since it has complete knowledge about the memory layout of S.<br class=""><br class="">Dmitri<br class=""><br class="">-- <br class="">main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if<br class="">(j){printf("%d\n",i);}}} /*Dmitri Gribenko <<a href="mailto:gribozavr@gmail.com" class="">gribozavr@gmail.com</a>>*/<br class=""></div></div></blockquote></div><br class=""><div class="">Sorry, it’s been a little while since I looked at it (<a href="https://github.com/apple/swift/pull/3067" class="">https://github.com/apple/swift/pull/3067</a>). Actually, the issue is with the append() function specifically - it only has a Sequence specialisation. That’s the point; we were losing type information and not calling the more optimised replaceSubrange — which is exactly the specialisation point you are talking about, Dmitry (I think everything funnels down in to replaceSubrange).</div><div class=""><br class=""></div><div class="">I must have misunderstood what you were saying at the time. I’ll have to test, but I think it’s still an issue. I thought there was some more general work on RRC planned, so when I saw the bullet I thought maybe that was it.</div><div class=""><br class=""></div><div class="">@Dave:</div><div class=""><br class=""></div><div class=""><div class="">I was trying to initialise a String.CharacterView - depending on whether I initialised it with another CharacterView, or created it empty and appended the other CharacterView, I would get huge performance differences, as the other CharacterView would get split up and a new Character created and appended for every character in the string (which had like 10,000 characters). It’s a subtle bug and a bit nasty when it hits you.</div></div><div class=""><br class=""></div><div class="">Karl</div><div class=""><br class=""></div><div class=""><br class=""></div></body></html>