Skip to content

Commit 02efc3a

Browse files
authored
Merge pull request #59899 from lorentey/unchecked-buffer-access-inside-strings
[stdlib] Switch to using unchecked buffer subscript in low-level Unicode helpers
2 parents c4aa00f + 64a57e3 commit 02efc3a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

stdlib/public/core/UnicodeHelpers.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ internal func _decodeUTF8(
6464
internal func _decodeScalar(
6565
_ utf16: UnsafeBufferPointer<UInt16>, startingAt i: Int
6666
) -> (Unicode.Scalar, scalarLength: Int) {
67-
let high = utf16[i]
67+
let high = utf16[_unchecked: i]
6868
if i + 1 >= utf16.count {
6969
_internalInvariant(!UTF16.isLeadSurrogate(high))
7070
_internalInvariant(!UTF16.isTrailSurrogate(high))
@@ -76,7 +76,7 @@ internal func _decodeScalar(
7676
return (Unicode.Scalar(_unchecked: UInt32(high)), 1)
7777
}
7878

79-
let low = utf16[i+1]
79+
let low = utf16[_unchecked: i+1]
8080
_internalInvariant(UTF16.isLeadSurrogate(high))
8181
_internalInvariant(UTF16.isTrailSurrogate(low))
8282
return (UTF16._decodeSurrogates(high, low), 2)
@@ -207,7 +207,7 @@ extension _StringGuts {
207207
@inlinable
208208
internal func fastUTF8ScalarLength(startingAt i: Int) -> Int {
209209
_internalInvariant(isFastUTF8)
210-
let len = _utf8ScalarLength(self.withFastUTF8 { $0[i] })
210+
let len = _utf8ScalarLength(self.withFastUTF8 { $0[_unchecked: i] })
211211
_internalInvariant((1...4) ~= len)
212212
return len
213213
}

0 commit comments

Comments
 (0)