One main motivation for
unsafeUninitializedCapacity was to call out Arrays of non-trivial types which require explicit initialization. This is non-obvious, e.g. users shouldn't use the subscript setter to initialize the elements: it will try to de-initialize uninitialized memory and result in UB. As @Karl mentioned, UTF-8 code units are trivial, so this is not a concern.
It can't be implemented entirely on the Swift 5.0 ABI. If this is made
@inlinable, it would further require the symbol for the cold path. In general, wouldn't the intermediate buffer approach defeat the point of this API in the non-small case?
If this is critical, we can consider doing something for the small case.
Alternative formulations could be a return
throws on the closure. The latter has some significant downsides, IIRC. This decision should be justified in the "Alternatives Considered" section.
@David_Smith, can you add justifications for "uninitializedCapacity", availability / inlinability, and zero convention on the closure return value?