Avoid StringUTF16View dispatch overhead for some bridged String methods (#83529)

This removes a bunch of overhead on the UTF16 paths in String, as well
as consolidating the complicated bits of the logic in one file.
This commit is contained in:
David Smith
2025-09-22 17:03:24 -07:00
committed by GitHub
parent b250ef7be3
commit 7b78a1d4b4
7 changed files with 104 additions and 49 deletions

View File

@@ -16,6 +16,7 @@
internal protocol _AbstractStringStorage: _NSCopying {
var asString: String { get }
var utf16: String.UTF16View { get }
var count: Int { get }
var isASCII: Bool { get }
var start: UnsafePointer<UInt8> { get }
@@ -26,6 +27,7 @@ internal protocol _AbstractStringStorage: _NSCopying {
internal protocol _AbstractStringStorage {
var asString: String { get }
var utf16: String.UTF16View { get }
var count: Int { get }
var isASCII: Bool { get }
var start: UnsafePointer<UInt8> { get }
@@ -295,6 +297,10 @@ final internal class __StringStorage
get { String(_StringGuts(self)) }
}
@inline(__always)
final internal var utf16: String.UTF16View {
String.UTF16View(_StringGuts(self))
}
private init(_doNotCallMe: ()) {
_internalInvariantFailure("Use the create method")
@@ -721,6 +727,11 @@ final internal class __SharedStringStorage
return String(_StringGuts(self))
}
}
@inline(__always)
final internal var utf16: String.UTF16View {
String.UTF16View(_StringGuts(self))
}
internal init(
_mortal ptr: UnsafePointer<UInt8>,