We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent bbcec6c commit a512ddfCopy full SHA for a512ddf
stdlib/public/core/Unicode.swift
@@ -629,11 +629,11 @@ public struct UTF32 : UnicodeCodec {
629
I : IteratorProtocol where I.Element == CodeUnit
630
>(_ input: inout I) -> UnicodeDecodingResult {
631
guard let x = input.next() else { return .emptyInput }
632
- if _fastPath((x >> 11) != 0b1101_1 && x <= 0x10ffff) {
633
- return .scalarValue(UnicodeScalar(x))
634
- } else {
635
- return .error
636
- }
+ // Check code unit is valid: not surrogate-reserved and within range.
+ guard _fastPath((x >> 11) != 0b1101_1 && x <= 0x10ffff)
+ else { return .error }
+ // x is a valid scalar.
+ return .scalarValue(UnicodeScalar(_unchecked: x))
637
}
638
639
/// Encodes a Unicode scalar as a UTF-32 code unit by calling the given
0 commit comments