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