Skip to content

Commit a850878

Browse files
committed
[ABI] Remove _HasContiguousBytes
1 parent f2c126a commit a850878

File tree

3 files changed

+13
-70
lines changed

3 files changed

+13
-70
lines changed

stdlib/public/core/ContiguouslyStored.swift

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -10,69 +10,6 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
@usableFromInline
14-
internal protocol _HasContiguousBytes {
15-
func withUnsafeBytes<R>(
16-
_ body: (UnsafeRawBufferPointer) throws -> R
17-
) rethrows -> R
18-
19-
var _providesContiguousBytesNoCopy: Bool { get }
20-
}
21-
extension _HasContiguousBytes {
22-
@inlinable
23-
var _providesContiguousBytesNoCopy: Bool {
24-
@inline(__always) get { return true }
25-
}
26-
}
27-
extension Array: _HasContiguousBytes {
28-
@inlinable
29-
var _providesContiguousBytesNoCopy: Bool {
30-
@inline(__always) get {
31-
#if _runtime(_ObjC)
32-
return _buffer._isNative
33-
#else
34-
return true
35-
#endif
36-
}
37-
}
38-
}
39-
extension ContiguousArray: _HasContiguousBytes {}
40-
extension UnsafeBufferPointer: _HasContiguousBytes {
41-
@inlinable @inline(__always)
42-
func withUnsafeBytes<R>(
43-
_ body: (UnsafeRawBufferPointer) throws -> R
44-
) rethrows -> R {
45-
let ptr = UnsafeRawPointer(self.baseAddress._unsafelyUnwrappedUnchecked)
46-
let len = self.count &* MemoryLayout<Element>.stride
47-
return try body(UnsafeRawBufferPointer(start: ptr, count: len))
48-
}
49-
}
50-
extension UnsafeMutableBufferPointer: _HasContiguousBytes {
51-
@inlinable @inline(__always)
52-
func withUnsafeBytes<R>(
53-
_ body: (UnsafeRawBufferPointer) throws -> R
54-
) rethrows -> R {
55-
let ptr = UnsafeRawPointer(self.baseAddress._unsafelyUnwrappedUnchecked)
56-
let len = self.count &* MemoryLayout<Element>.stride
57-
return try body(UnsafeRawBufferPointer(start: ptr, count: len))
58-
}
59-
}
60-
extension UnsafeRawBufferPointer: _HasContiguousBytes {
61-
@inlinable @inline(__always)
62-
func withUnsafeBytes<R>(
63-
_ body: (UnsafeRawBufferPointer) throws -> R
64-
) rethrows -> R {
65-
return try body(self)
66-
}
67-
}
68-
extension UnsafeMutableRawBufferPointer: _HasContiguousBytes {
69-
@inlinable @inline(__always)
70-
func withUnsafeBytes<R>(
71-
_ body: (UnsafeRawBufferPointer) throws -> R
72-
) rethrows -> R {
73-
return try body(UnsafeRawBufferPointer(self))
74-
}
75-
}
7613
extension String {
7714

7815
@inlinable @inline(__always)

stdlib/public/core/String.swift

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -401,13 +401,11 @@ extension String {
401401
public init<C: Collection, Encoding: Unicode.Encoding>(
402402
decoding codeUnits: C, as sourceEncoding: Encoding.Type
403403
) where C.Iterator.Element == Encoding.CodeUnit {
404-
if let contigBytes = codeUnits as? _HasContiguousBytes,
405-
sourceEncoding == UTF8.self,
406-
contigBytes._providesContiguousBytesNoCopy
407-
{
408-
self = contigBytes.withUnsafeBytes { rawBufPtr -> String in
409-
return String._fromUTF8Repairing(rawBufPtr).0
410-
}
404+
if sourceEncoding == UTF8.self,
405+
let str = codeUnits._withRawContiguousStorageIfAvailable({
406+
buf -> String in String._fromUTF8Repairing(buf).0
407+
}) {
408+
self = str
411409
return
412410
}
413411

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,11 @@ Struct Substring has removed conformance to _HasContiguousBytes
9696
Var String._providesContiguousBytesNoCopy has been removed
9797
Var Substring._providesContiguousBytesNoCopy has been removed
9898
Func Sequence._withRawContiguousStorageIfAvailable(_:) has been added as a protocol requirement
99+
Func UnsafeBufferPointer.withUnsafeBytes(_:) has been removed
100+
Func UnsafeMutableBufferPointer.withUnsafeBytes(_:) has been removed
101+
Protocol _HasContiguousBytes has been removed
102+
Struct Array has removed conformance to _HasContiguousBytes
103+
Struct ContiguousArray has removed conformance to _HasContiguousBytes
104+
Struct UnsafeBufferPointer has removed conformance to _HasContiguousBytes
105+
Struct UnsafeMutableBufferPointer has removed conformance to _HasContiguousBytes
106+
Var Array._providesContiguousBytesNoCopy has been removed

0 commit comments

Comments
 (0)