on Thu Jun 15 2017, Arnold <aschwaighofer-AT-apple.com> wrote: >> On Jun 14, 2017, at 2:56 PM, Dave Abrahams via swift-dev >> <swift-dev@swift.org> wrote: >> >> >>> on Wed Jun 14 2017, Erik Eckstein <swift-dev-AT-swift.org> wrote: >>> >>> Hi, >>> >>> I’m about implementing statically initialized arrays. It’s about >>> allocating storage for arrays in the data section rather than on the >>> heap. >> >> W00t! I'd like to do the same for String, i.e. encode the entire buffer >> in the data section. I was looking for Array example code to follow but >> couldn't find it. > > We have support for constant string buffers as of PR 8701 and PR > 8692. The former PR shows the protocol that has to be implemented. > > (The implementation currently exposes the ref count ABI. This > can/needs to be fixed when we move to a stable abi by running an once > initializer) >> >>> Info: the array storage is a heap object. So in the following I’m >>> using the general term “object” but the optimization will (probably) >>> only handle array buffers. >>> >>> This optimization can be done for array literals containing only other >>> literals as elements. Example: >>> >>> func createArray() -> [Int] { >>> return [1, 2, 3] >>> } >>> >>> The compiler can allocate the whole array buffer as a statically >>> initialized global llvm-variable with a reference count of 2 to make >>> it immortal. >> >> Why not 1 > > Mutation must force copying.
I know, but I assumed each reference formed to this buffer would increment the reference count. -- -Dave _______________________________________________ swift-dev mailing list swift-dev@swift.org https://lists.swift.org/mailman/listinfo/swift-dev