Skip to content

[5.7][stdlib] Switch to using unchecked buffer subscript in low-level Unicode helpers #59901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions stdlib/public/core/UnicodeHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ internal func _decodeUTF8(
internal func _decodeScalar(
_ utf16: UnsafeBufferPointer<UInt16>, startingAt i: Int
) -> (Unicode.Scalar, scalarLength: Int) {
let high = utf16[i]
let high = utf16[_unchecked: i]
if i + 1 >= utf16.count {
_internalInvariant(!UTF16.isLeadSurrogate(high))
_internalInvariant(!UTF16.isTrailSurrogate(high))
Expand All @@ -76,7 +76,7 @@ internal func _decodeScalar(
return (Unicode.Scalar(_unchecked: UInt32(high)), 1)
}

let low = utf16[i+1]
let low = utf16[_unchecked: i+1]
_internalInvariant(UTF16.isLeadSurrogate(high))
_internalInvariant(UTF16.isTrailSurrogate(low))
return (UTF16._decodeSurrogates(high, low), 2)
Expand Down Expand Up @@ -207,7 +207,7 @@ extension _StringGuts {
@inlinable
internal func fastUTF8ScalarLength(startingAt i: Int) -> Int {
_internalInvariant(isFastUTF8)
let len = _utf8ScalarLength(self.withFastUTF8 { $0[i] })
let len = _utf8ScalarLength(self.withFastUTF8 { $0[_unchecked: i] })
_internalInvariant((1...4) ~= len)
return len
}
Expand Down