Skip to content

Commit 19075e0

Browse files
committed
[ABI] Clean up StringCreate, remove unused _HasContiguousBytes
conformance from String/Substring.
1 parent bcb874c commit 19075e0

File tree

4 files changed

+15
-52
lines changed

4 files changed

+15
-52
lines changed

stdlib/public/core/AssertCommon.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ internal func _assertionFailure(
115115
) -> Never {
116116
prefix.withUTF8Buffer {
117117
(prefix) -> Void in
118-
message._withUnsafeBufferPointerToUTF8 {
118+
message._withUTF8 {
119119
(messageUTF8) -> Void in
120120
file.withUTF8Buffer {
121121
(file) -> Void in
@@ -145,7 +145,7 @@ internal func _assertionFailure(
145145
) -> Never {
146146
prefix.withUTF8Buffer {
147147
(prefix) -> Void in
148-
message._withUnsafeBufferPointerToUTF8 {
148+
message._withUTF8 {
149149
(messageUTF8) -> Void in
150150
_swift_stdlib_reportFatalError(
151151
prefix.baseAddress!, CInt(prefix.count),

stdlib/public/core/ContiguouslyStored.swift

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,7 @@ extension UnsafeMutableRawBufferPointer: _HasContiguousBytes {
7373
return try body(UnsafeRawBufferPointer(self))
7474
}
7575
}
76-
extension String: _HasContiguousBytes {
77-
@inlinable
78-
internal var _providesContiguousBytesNoCopy: Bool {
79-
@inline(__always) get { return self._guts.isFastUTF8 }
80-
}
76+
extension String {
8177

8278
@inlinable @inline(__always)
8379
internal func _withUTF8<R>(
@@ -93,20 +89,9 @@ extension String: _HasContiguousBytes {
9389
try body($0)
9490
}
9591
}
96-
97-
@inlinable @inline(__always)
98-
internal func withUnsafeBytes<R>(
99-
_ body: (UnsafeRawBufferPointer) throws -> R
100-
) rethrows -> R {
101-
return try self._withUTF8 { return try body(UnsafeRawBufferPointer($0)) }
102-
}
10392
}
104-
extension Substring: _HasContiguousBytes {
105-
@inlinable
106-
internal var _providesContiguousBytesNoCopy: Bool {
107-
@inline(__always) get { return self._wholeGuts.isFastUTF8 }
108-
}
109-
93+
extension Substring {
94+
11095
@inlinable @inline(__always)
11196
internal func _withUTF8<R>(
11297
_ body: (UnsafeBufferPointer<UInt8>) throws -> R
@@ -121,11 +106,4 @@ extension Substring: _HasContiguousBytes {
121106
try body($0)
122107
}
123108
}
124-
125-
@inlinable @inline(__always)
126-
internal func withUnsafeBytes<R>(
127-
_ body: (UnsafeRawBufferPointer) throws -> R
128-
) rethrows -> R {
129-
return try self._withUTF8 { return try body(UnsafeRawBufferPointer($0)) }
130-
}
131109
}

stdlib/public/core/StringCreate.swift

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,7 @@ extension String {
5858
_ input: UnsafeBufferPointer<UInt8>
5959
) -> String {
6060
_internalInvariant(_allASCII(input), "not actually ASCII")
61-
62-
if let smol = _SmallString(input) {
63-
return String(_StringGuts(smol))
64-
}
65-
66-
let storage = __StringStorage.create(initializingFrom: input, isASCII: true)
67-
return storage.asString
61+
return _uncheckedFromUTF8(UnsafeRawBufferPointer(input), isASCII: true)
6862
}
6963

7064
// UTF8 from typed memory.
@@ -113,8 +107,7 @@ extension String {
113107
}
114108
}
115109

116-
@usableFromInline
117-
internal static func _uncheckedFromUTF8(
110+
private static func _uncheckedFromUTF8(
118111
_ input: UnsafeRawBufferPointer,
119112
isASCII: Bool
120113
) -> String {
@@ -127,15 +120,6 @@ extension String {
127120
return storage.asString
128121
}
129122

130-
// If we've already pre-scanned for ASCII, just supply the result
131-
@usableFromInline
132-
internal static func _uncheckedFromUTF8(
133-
_ input: UnsafeBufferPointer<UInt8>, asciiPreScanResult: Bool
134-
) -> String {
135-
return _uncheckedFromUTF8(UnsafeRawBufferPointer(input),
136-
isASCII: asciiPreScanResult)
137-
}
138-
139123
// Other encodings.
140124

141125
@usableFromInline
@@ -159,12 +143,6 @@ extension String {
159143
return contents.withUnsafeBufferPointer { String._uncheckedFromUTF8($0) }
160144
}
161145

162-
internal func _withUnsafeBufferPointerToUTF8<R>(
163-
_ body: (UnsafeBufferPointer<UTF8.CodeUnit>) throws -> R
164-
) rethrows -> R {
165-
return try self._withUTF8(body)
166-
}
167-
168146
@usableFromInline @inline(never) // slow-path
169147
internal static func _fromCodeUnits<
170148
Input: Collection,

test/api-digester/Outputs/stability-stdlib-abi.swift.expected

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,12 @@ Subscript Substring.subscript(_:) has been removed
8686

8787
Func Collection.makeIterator() has self access kind changing from NonMutating to __Consuming
8888

89-
Func String._uncheckedFromUTF8(_:isASCII:) has parameter 0 type change from UnsafeBufferPointer<UInt8> to UnsafeRawBufferPointer
89+
Func String._uncheckedFromUTF8(_:isASCII:) has been removed
9090
Func _bytesToUInt64(_:_:) has parameter 0 type change from UnsafePointer<UInt8> to UnsafeRawPointer
91+
Func String._uncheckedFromUTF8(_:asciiPreScanResult:) has been removed
92+
Func String.withUnsafeBytes(_:) has been removed
93+
Func Substring.withUnsafeBytes(_:) has been removed
94+
Struct String has removed conformance to _HasContiguousBytes
95+
Struct Substring has removed conformance to _HasContiguousBytes
96+
Var String._providesContiguousBytesNoCopy has been removed
97+
Var Substring._providesContiguousBytesNoCopy has been removed

0 commit comments

Comments
 (0)