[String] Drop in initial UTF-8 String prototype

This is a giant squashing of a lot of individual changes prototyping a
switch of String in Swift 5 to be natively encoded as UTF-8. It
includes what's necessary for a functional prototype, dropping some
history, but still leaves plenty of history available for future
commits.

My apologies to anyone trying to do code archeology between this
commit and the one prior. This was the lesser of evils.
This commit is contained in:
Michael Ilseman
2018-11-03 16:23:37 -07:00
parent b2f60bf978
commit 4ab45dfe20
46 changed files with 4320 additions and 10315 deletions

View File

@@ -23,6 +23,7 @@ struct _StringRepresentation {
case _cocoa(object: AnyObject)
case _native(object: AnyObject)
case _immortal(address: UInt)
// TODO: shared native
}
public var _form: _Form
@@ -37,27 +38,35 @@ struct _StringRepresentation {
extension String {
public // @testable
func _classify() -> _StringRepresentation {
func _classify() -> _StringRepresentation { return _guts._classify() }
}
extension _StringGuts {
internal func _classify() -> _StringRepresentation {
var result = _StringRepresentation(
_isASCII: _guts._isASCIIOrSmallASCII,
_count: _guts.count,
_capacity: _guts.capacity,
_isASCII: self.isKnownASCII,
_count: self.count,
_capacity: self.capacity ?? 0,
_form: ._small
)
if _guts._isSmall {
if _object.isSmall {
return result
}
if _guts._isNative {
result._form = ._native(object: _guts._owner!)
if _object.largeIsCocoa {
result._form = ._cocoa(object: _object.cocoaObject)
return result
}
if _guts._isCocoa {
result._form = ._cocoa(object: _guts._owner!)
return result
}
if _guts._isUnmanaged {
// TODO: shared native
_sanityCheck(_object.providesFastUTF8)
_sanityCheck(_object.largeFastIsNative)
if _object.isImmortal {
result._form = ._immortal(
address: UInt(bitPattern: _guts._unmanagedRawStart))
address: UInt(bitPattern: _object.nativeUTF8Start))
return result
}
if _object.hasNativeStorage {
result._form = ._native(object: _object.nativeStorage)
return result
}
fatalError()