@@ -440,7 +440,7 @@ public struct UTF16 : UnicodeCodec {
440
440
public init ( ) { }
441
441
442
442
/// A lookahead buffer for one UTF-16 code unit.
443
- internal var _decodeLookahead : UInt32 ?
443
+ internal var _decodeLookahead : UInt16 ?
444
444
445
445
/// Starts or continues decoding a UTF-16 sequence.
446
446
///
@@ -490,10 +490,10 @@ public struct UTF16 : UnicodeCodec {
490
490
// length 1. Length 0 does not make sense. Neither does length 2 -- in
491
491
// that case the sequence is valid.
492
492
493
- let unit0 : UInt32
493
+ let unit0 : UInt16
494
494
if _fastPath ( _decodeLookahead == nil ) {
495
495
guard let next = input. next ( ) else { return . emptyInput }
496
- unit0 = UInt32 ( next)
496
+ unit0 = next
497
497
} else { // Consume lookahead first.
498
498
unit0 = _decodeLookahead!
499
499
_decodeLookahead = nil
@@ -505,15 +505,14 @@ public struct UTF16 : UnicodeCodec {
505
505
506
506
// Common case first, non-surrogate -- just a sequence of 1 code unit.
507
507
if _fastPath ( ( unit0 >> 11 ) != 0b1101_1 ) {
508
- return . scalarValue( UnicodeScalar ( _unchecked: unit0) )
508
+ return . scalarValue( UnicodeScalar ( _unchecked: UInt32 ( unit0) ) )
509
509
}
510
510
511
511
// Ensure `unit0` is a high-surrogate.
512
512
guard _fastPath ( ( unit0 >> 10 ) == 0b1101_10 ) else { return . error }
513
513
514
514
// We already have a high-surrogate, so there should be a next code unit.
515
- guard let next = input. next ( ) else { return . error }
516
- let unit1 = UInt32 ( next)
515
+ guard let unit1 = input. next ( ) else { return . error }
517
516
518
517
// `unit0` is a high-surrogate, so `unit1` should be a low-surrogate.
519
518
guard _fastPath ( ( unit1 >> 10 ) == 0b1101_11 ) else {
@@ -523,7 +522,7 @@ public struct UTF16 : UnicodeCodec {
523
522
}
524
523
525
524
// We have a well-formed surrogate pair, decode it.
526
- let result = 0x10000 + ( ( ( unit0 & 0x03ff ) << 10 ) | ( unit1 & 0x03ff ) )
525
+ let result = 0x10000 + ( ( UInt32 ( unit0 & 0x03ff ) << 10 ) | UInt32 ( unit1 & 0x03ff ) )
527
526
return . scalarValue( UnicodeScalar ( _unchecked: result) )
528
527
}
529
528
0 commit comments