[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:
Dave Abrahams
2017-06-01 18:52:21 -07:00
parent b218378e87
commit 562fd79aa6
5 changed files with 156 additions and 241 deletions

View File

@@ -702,13 +702,11 @@ extension String.CharacterView : RangeReplaceableCollection {
///
/// - Parameter c: The character to append to the character view.
public mutating func append(_ c: Character) {
switch c._representation {
case .small(let _63bits):
let bytes = Character._smallValue(_63bits)
_core.append(contentsOf: Character._SmallUTF16(bytes))
case .large(_):
_core.append(String(c)._core)
if let c0 = c._smallUTF16 {
_core.append(contentsOf: c0)
return
}
_core.append(c._largeUTF16!)
}
/// Appends the characters in the given sequence to the character view.