mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[stdlib] Encode small Characters as UTF-16
This takes care of the standard library portion, but we need a new BuiltinUTF16ExtendedGraphemeClusterLiteralConvertible protocol in order to fully recover the performance of character literals. Note that part of the character_literals.swift test is currently disabled. That will need to be fixed before we can merge this work.
This commit is contained in:
@@ -120,3 +120,50 @@ extension Unicode._ParsingIterator : IteratorProtocol, Sequence {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
extension Unicode {
|
||||
@_fixed_layout
|
||||
@_versioned
|
||||
internal struct _TranscodingIterator<
|
||||
SourceCodeUnits : IteratorProtocol,
|
||||
Parser : Unicode.Parser,
|
||||
TargetEncoding : Unicode.Encoding
|
||||
> where Parser.Encoding.CodeUnit == SourceCodeUnits.Element {
|
||||
|
||||
@inline(__always)
|
||||
@_inlineable
|
||||
public init(source: SourceCodeUnits, parser: Parser) {
|
||||
_scalars = _ParsingIterator(codeUnits: source, parser: parser)
|
||||
let firstScalar_ = _scalars.next()
|
||||
if _fastPath(firstScalar_ != nil), let firstScalar = firstScalar_ {
|
||||
_codeUnits = TargetEncoding._transcode(
|
||||
firstScalar, from: Parser.Encoding.self).makeIterator()
|
||||
}
|
||||
else {
|
||||
_codeUnits = TargetEncoding._encode(
|
||||
UnicodeScalar(_unchecked: 0)).makeIterator()
|
||||
while _codeUnits.next() != nil { }
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
internal var _scalars: _ParsingIterator<SourceCodeUnits, Parser>
|
||||
internal var _codeUnits: TargetEncoding.EncodedScalar.Iterator
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extension Unicode._TranscodingIterator : IteratorProtocol, Sequence {
|
||||
@inline(__always)
|
||||
@_inlineable
|
||||
mutating public func next() -> TargetEncoding.CodeUnit? {
|
||||
if let x = _codeUnits.next() { return x }
|
||||
let nextScalar_ = _scalars.next()
|
||||
if _fastPath(nextScalar_ != nil), let nextScalar = nextScalar_ {
|
||||
_codeUnits = TargetEncoding._transcode(
|
||||
nextScalar, from: Parser.Encoding.self).makeIterator()
|
||||
}
|
||||
return _codeUnits.next()
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user