swift
b5f018a4 - Mark Array.withUnsafeMutableBuffer as not escaping the array storage.

Commit
9 years ago
Mark Array.withUnsafeMutableBuffer as not escaping the array storage. This is safe because the closure is not allowed to capture the array according to the documentation of 'withUnsafeMutableBuffer' and the current implementation makes sure that any such capture would observe an empty array by swapping self with an empty array. Users will get "almost guaranteed" stack promotion for small arrays by writing something like: func testStackAllocation(p: Proto) { var a = [p, p, p] a.withUnsafeMutableBufferPointer { let array = $0 work(array) } } It is "almost guaranteed" because we need to statically be able to tell the size required for the array (no unspecialized generics) and the total buffer size must not exceed 1K.
Author
Committer
Parents
Loading