Skip to content

Commit 1abd2e0

Browse files
author
Dave Abrahams
committed
[stdlib] UnicodeDecoders: Hoist _isScalar() up to UnicodeEncoding
1 parent 23f51e6 commit 1abd2e0

File tree

1 file changed

+6
-23
lines changed

1 file changed

+6
-23
lines changed

test/Prototypes/UnicodeDecoders.swift

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,6 @@ where Encoding.EncodedScalar == _UIntBuffer<_UInt32, Encoding.CodeUnit>,
520520
_UInt32 == UInt32
521521
{
522522
associatedtype _UInt32 = UInt32
523-
static func _isScalar(_: Encoding.CodeUnit) -> Bool
524523
func _parseMultipleCodeUnits() -> (isValid: Bool, bitCount: UInt8)
525524
var buffer: Encoding.EncodedScalar { get set }
526525
func _bufferedScalar(bitCount: UInt8) -> Encoding.EncodedScalar
@@ -536,12 +535,12 @@ extension _UTFDecoder where Encoding.EncodedScalar == _UIntBuffer<UInt32, Encodi
536535
if _fastPath(buffer.isEmpty) {
537536
guard let codeUnit = input.next() else { return .emptyInput }
538537
// ASCII, return immediately.
539-
if Self._isScalar(codeUnit) {
538+
if Encoding._isScalar(codeUnit) {
540539
return .valid(Encoding.EncodedScalar(containing: codeUnit))
541540
}
542541
// Non-ASCII, proceed to buffering mode.
543542
buffer.append(codeUnit)
544-
} else if Self._isScalar(Encoding.CodeUnit(extendingOrTruncating: buffer._storage)) {
543+
} else if Encoding._isScalar(Encoding.CodeUnit(extendingOrTruncating: buffer._storage)) {
545544
// ASCII in buffer. We don't refill the buffer so we can return
546545
// to bufferless mode once we've exhausted it.
547546
let codeUnit = Encoding.CodeUnit(extendingOrTruncating: buffer._storage)
@@ -587,13 +586,6 @@ extension _UTFDecoder where Encoding.EncodedScalar == _UIntBuffer<UInt32, Encodi
587586
//===--- UTF8 Decoders ----------------------------------------------------===//
588587
//===----------------------------------------------------------------------===//
589588

590-
public protocol _UTF8Decoder : _UTFDecoder {
591-
}
592-
593-
extension _UTF8Decoder {
594-
public static func _isScalar(_ x: Encoding.CodeUnit) -> Bool { return x & 0x80 == 0 }
595-
}
596-
597589
extension Unicode.UTF8 : UnicodeEncoding {
598590
public typealias EncodedScalar = _UIntBuffer<UInt32, UInt8>
599591

@@ -640,7 +632,7 @@ extension Unicode.UTF8 : UnicodeEncoding {
640632
}
641633
}
642634

643-
extension UTF8.ReverseDecoder : _UTF8Decoder {
635+
extension UTF8.ReverseDecoder : _UTFDecoder {
644636
public typealias Encoding = Unicode.UTF8
645637

646638
public // @testable
@@ -715,7 +707,7 @@ extension UTF8.ReverseDecoder : _UTF8Decoder {
715707
}
716708

717709
extension
718-
Unicode.UTF8.ForwardDecoder : _UTF8Decoder {
710+
Unicode.UTF8.ForwardDecoder : _UTFDecoder {
719711
public typealias Encoding = Unicode.UTF8
720712

721713
public // @testable
@@ -786,15 +778,6 @@ extension
786778
//===--- UTF-16 Decoders --------------------------------------------------===//
787779
//===----------------------------------------------------------------------===//
788780

789-
public protocol _UTF16Decoder : _UTFDecoder where Encoding.CodeUnit == UTF16.CodeUnit {
790-
}
791-
792-
extension _UTF16Decoder {
793-
public static func _isScalar(_ x: Encoding.CodeUnit) -> Bool {
794-
return x & 0xf800 != 0xd800
795-
}
796-
}
797-
798781
extension Unicode.UTF16 : UnicodeEncoding {
799782
public typealias EncodedScalar = _UIntBuffer<UInt32, UInt16>
800783

@@ -829,7 +812,7 @@ extension Unicode.UTF16 : UnicodeEncoding {
829812
}
830813
}
831814

832-
extension UTF16.ReverseDecoder : _UTF16Decoder {
815+
extension UTF16.ReverseDecoder : _UTFDecoder {
833816
public typealias Encoding = Unicode.UTF16
834817

835818
public // @testable
@@ -851,7 +834,7 @@ extension UTF16.ReverseDecoder : _UTF16Decoder {
851834
}
852835
}
853836

854-
extension Unicode.UTF16.ForwardDecoder : _UTF16Decoder {
837+
extension Unicode.UTF16.ForwardDecoder : _UTFDecoder {
855838
public typealias Encoding = Unicode.UTF16
856839

857840
public // @testable

0 commit comments

Comments
 (0)