[swift-evolution] [Swift 3?] Add ContiguousArray -> Array non-copying initialiser
Karl Wagner
razielim at gmail.com
Thu Jul 28 13:01:08 CDT 2016
I didn't know that normally-copying initialiser was non-copying for ContiguousArray. That's the kind of thing we should really document somewhere (or it should be it's own function because it guarantees non-copying behaviour).
If you're using CA explicitly, it's because you want those subtle performance guarantees.
Karl
Sent from my new Email (https://itunes.apple.com/app/apple-store/id922793622?pt=814382&mt=8&ct=my_new_email)
>
> On Jul 28, 2016 at 10:32 AM, <Dmitri Gribenko (mailto:gribozavr at gmail.com)> wrote:
>
>
>
> On Wed, Jul 27, 2016 at 11:08 PM, Karl via swift-evolution
> <swift-evolution at swift.org (mailto:swift-evolution at swift.org)> wrote:
> > It seems like a reasonably large hole with a simple fix. Going from
> > ContiguousArray to Array is a kind-of upcasting conversion and should be
> > allowed -- it seems like that's almost the whole point of the type.
>
> Hi Karl,
>
> Converting a ContiguousArray to Array using Array's initializer is
> O(1). Are you seeing something different?
>
> Array.init:
>
> https://github.com/apple/swift/blob/f8f6d61d195185f54aeba425dd0db8be4c5d163f/stdlib/public/core/Arrays.swift.gyb#L1037
>
> ContiguousArray._copyToContiguousArray():
>
> https://github.com/apple/swift/blob/f8f6d61d195185f54aeba425dd0db8be4c5d163f/stdlib/public/core/Arrays.swift.gyb#L1430
>
> Dmitri
>
> --
> main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
> (j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com (mailto:gribozavr at gmail.com)>*/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160728/cfdbd8b8/attachment.html>
More information about the swift-evolution
mailing list