[String] Add UTF-8 fast-paths for Foundation initializers

Many Foundation initializers could benefit from faster string
construction and subsequent reads in Swift 5. Add UTF-8 fast paths for
when constructing a string from a valid UTF-8 code units.
This commit is contained in:
Michael Ilseman
2019-01-17 14:14:05 -08:00
parent a628d5d76a
commit a088e13224
2 changed files with 28 additions and 8 deletions

View File

@@ -42,12 +42,10 @@ extension String {
return storage.asString
}
@usableFromInline
internal static func _tryFromUTF8(
_ input: UnsafeBufferPointer<UInt8>
) -> String? {
public // SPI(Foundation)
static func _tryFromUTF8(_ input: UnsafeBufferPointer<UInt8>) -> String? {
guard case .success(let extraInfo) = validateUTF8(input) else {
return nil
return nil
}
return String._uncheckedFromUTF8(input, isASCII: extraInfo.isASCII)