mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Merge pull request #41869 from Catfish-Man/stack-promotion-and-ar-raise
Use withUnsafeTemporaryAllocation instead of a temporary Array
This commit is contained in:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user