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))
|
).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")
|
||||||
|
|||||||
Reference in New Issue
Block a user