mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user