Oh that's right, there's this warning in UnsafeMutablePointer.subscript(_:)
Do not assign an instance of a nontrivial type through the subscript to uninitialized memory. Instead, use an initializing method, such as initialize(to:count:).
Which doesn't appear in UnsafeMutableBufferPointer
version. Either Buffer
version has better handling or the it missed the warning. I'm gonna assume the latter, but maybe someone more knowledgeable can chime in.
This may be related, so you may want to instead use UnsafeMutablePointer.initialized(to:)
.
let array: [Element] = try Array(unsafeUninitializedCapacity: count) { (buffer, countToAssign) in
var address = buffer.baseAddress!
defer {
countToAssign = address - buffer.baseAddress!
}
for _ in 0..<count {
try addess.initialize(to: Element(from: decoder))
address = address.successor()
JNTDocumentNextArrayElement(currentValue, &isAtEnd)
}
}