Skip to content

Commit a512ddf

Browse files
Refactor UTF32.decode for consistency with UTF8/UTF16
1 parent bbcec6c commit a512ddf

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

stdlib/public/core/Unicode.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -629,11 +629,11 @@ public struct UTF32 : UnicodeCodec {
629629
I : IteratorProtocol where I.Element == CodeUnit
630630
>(_ input: inout I) -> UnicodeDecodingResult {
631631
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-
}
632+
// Check code unit is valid: not surrogate-reserved and within range.
633+
guard _fastPath((x >> 11) != 0b1101_1 && x <= 0x10ffff)
634+
else { return .error }
635+
// x is a valid scalar.
636+
return .scalarValue(UnicodeScalar(_unchecked: x))
637637
}
638638

639639
/// Encodes a Unicode scalar as a UTF-32 code unit by calling the given

0 commit comments

Comments
 (0)