File tree Expand file tree Collapse file tree 1 file changed +6
-8
lines changed Expand file tree Collapse file tree 1 file changed +6
-8
lines changed Original file line number Diff line number Diff line change @@ -396,17 +396,15 @@ extension _StringGuts {
396
396
) . 0 ) )
397
397
}
398
398
399
- // TODO(String performance): Stack buffer if small enough
400
- let cus = Array < UInt16 > ( unsafeUninitializedCapacity : count) {
401
- buffer, initializedCapacity in
399
+ return withUnsafeTemporaryAllocation (
400
+ of : UInt16 . self , capacity : count
401
+ ) { buffer in
402
402
_cocoaStringCopyCharacters (
403
403
from: self . _object. cocoaObject,
404
404
range: start..< end,
405
- into: buffer. baseAddress. _unsafelyUnwrappedUnchecked)
406
- initializedCapacity = count
407
- }
408
- return cus. withUnsafeBufferPointer {
409
- return Character ( String . _uncheckedFromUTF16 ( $0) )
405
+ into: buffer. baseAddress. _unsafelyUnwrappedUnchecked
406
+ )
407
+ return Character ( String . _uncheckedFromUTF16 ( UnsafeBufferPointer ( buffer) ) )
410
408
}
411
409
#else
412
410
fatalError ( " No foreign strings on Linux in this version of Swift " )
You can’t perform that action at this time.
0 commit comments