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 {
396396 ) . 0 ) )
397397 }
398398
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
402402 _cocoaStringCopyCharacters (
403403 from: self . _object. cocoaObject,
404404 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) ) )
410408 }
411409#else
412410 fatalError ( " No foreign strings on Linux in this version of Swift " )
You can’t perform that action at this time.
0 commit comments