Merge pull request #41869 from Catfish-Man/stack-promotion-and-ar-raise

Use withUnsafeTemporaryAllocation instead of a temporary Array
This commit is contained in:
David Smith
2022-03-18 16:27:31 -07:00
committed by GitHub

View File

@@ -396,17 +396,15 @@ extension _StringGuts {
).0))
}
// TODO(String performance): Stack buffer if small enough
let cus = Array<UInt16>(unsafeUninitializedCapacity: count) {
buffer, initializedCapacity in
return withUnsafeTemporaryAllocation(
of: UInt16.self, capacity: count
) { buffer in
_cocoaStringCopyCharacters(
from: self._object.cocoaObject,
range: start..<end,
into: buffer.baseAddress._unsafelyUnwrappedUnchecked)
initializedCapacity = count
}
return cus.withUnsafeBufferPointer {
return Character(String._uncheckedFromUTF16($0))
into: buffer.baseAddress._unsafelyUnwrappedUnchecked
)
return Character(String._uncheckedFromUTF16(UnsafeBufferPointer(buffer)))
}
#else
fatalError("No foreign strings on Linux in this version of Swift")