Skip to content

Commit 2dcbc53

Browse files
committed
Removes redundant buffer zeroing in foreignErrorCorrectedGrapheme func
1 parent 843a584 commit 2dcbc53

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

stdlib/public/core/UnicodeHelpers.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,12 +397,13 @@ extension _StringGuts {
397397
}
398398

399399
// TODO(String performance): Stack buffer if small enough
400-
var cus = Array<UInt16>(repeating: 0, count: count)
401-
cus.withUnsafeMutableBufferPointer {
400+
let cus = Array<UInt16>(unsafeUninitializedCapacity: count) {
401+
buffer, initializedCapacity in
402402
_cocoaStringCopyCharacters(
403403
from: self._object.cocoaObject,
404404
range: start..<end,
405-
into: $0.baseAddress._unsafelyUnwrappedUnchecked)
405+
into: buffer.baseAddress._unsafelyUnwrappedUnchecked)
406+
initializedCapacity = count
406407
}
407408
return cus.withUnsafeBufferPointer {
408409
return Character(String._uncheckedFromUTF16($0))

0 commit comments

Comments
 (0)