Skip to content

Commit 81fb49e

Browse files
committed
stdlib: mark some Array buffers implementation details as internal
1 parent 4755800 commit 81fb49e

File tree

3 files changed

+29
-32
lines changed

3 files changed

+29
-32
lines changed

stdlib/public/core/ArrayBuffer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public struct _ArrayBuffer<Element> : _ArrayBufferProtocol {
8383

8484
extension _ArrayBuffer {
8585
/// Adopt the storage of `source`.
86-
public init(_buffer source: NativeBuffer, shiftedToStartIndex: Int) {
86+
internal init(_buffer source: NativeBuffer, shiftedToStartIndex: Int) {
8787
_sanityCheck(shiftedToStartIndex == 0, "shiftedToStartIndex must be 0")
8888
_storage = _ArrayBridgeStorage(native: source._storage)
8989
}

stdlib/public/core/ContiguousArrayBuffer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ struct _ContiguousArrayBuffer<Element> : _ArrayBufferProtocol {
287287
_uncheckedUnsafeBufferObject: _emptyArrayStorage)
288288
}
289289

290-
public init(_buffer buffer: _ContiguousArrayBuffer, shiftedToStartIndex: Int) {
290+
internal init(_buffer buffer: _ContiguousArrayBuffer, shiftedToStartIndex: Int) {
291291
_sanityCheck(shiftedToStartIndex == 0, "shiftedToStartIndex must be 0")
292292
self = buffer
293293
}

stdlib/public/core/SliceBuffer.swift

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
public // @testable
1515
struct _SliceBuffer<Element> : _ArrayBufferProtocol, RandomAccessCollection {
1616
internal typealias NativeStorage = _ContiguousArrayStorage<Element>
17-
public typealias NativeBuffer = _ContiguousArrayBuffer<Element>
17+
internal typealias NativeBuffer = _ContiguousArrayBuffer<Element>
1818

19-
init(
19+
internal init(
2020
owner: AnyObject, subscriptBaseAddress: UnsafeMutablePointer<Element>,
2121
indices: Range<Int>, hasNativeBuffer: Bool
2222
) {
@@ -28,7 +28,7 @@ struct _SliceBuffer<Element> : _ArrayBufferProtocol, RandomAccessCollection {
2828
_invariantCheck()
2929
}
3030

31-
public init() {
31+
internal init() {
3232
let empty = _ContiguousArrayBuffer<Element>()
3333
self.owner = empty.owner
3434
self.subscriptBaseAddress = empty.firstElementAddress
@@ -37,7 +37,7 @@ struct _SliceBuffer<Element> : _ArrayBufferProtocol, RandomAccessCollection {
3737
_invariantCheck()
3838
}
3939

40-
public init(_buffer buffer: NativeBuffer, shiftedToStartIndex: Int) {
40+
internal init(_buffer buffer: NativeBuffer, shiftedToStartIndex: Int) {
4141
let shift = buffer.startIndex - shiftedToStartIndex
4242
self.init(
4343
owner: buffer.owner,
@@ -46,7 +46,7 @@ struct _SliceBuffer<Element> : _ArrayBufferProtocol, RandomAccessCollection {
4646
hasNativeBuffer: true)
4747
}
4848

49-
func _invariantCheck() {
49+
internal func _invariantCheck() {
5050
let isNative = _hasNativeBuffer
5151
let isNativeStorage: Bool = (owner as? _ContiguousArrayStorageBase) != nil
5252
_sanityCheck(isNativeStorage == isNative)
@@ -55,17 +55,17 @@ struct _SliceBuffer<Element> : _ArrayBufferProtocol, RandomAccessCollection {
5555
}
5656
}
5757

58-
var _hasNativeBuffer: Bool {
58+
internal var _hasNativeBuffer: Bool {
5959
return (endIndexAndFlags & 1) != 0
6060
}
6161

62-
var nativeBuffer: NativeBuffer {
62+
internal var nativeBuffer: NativeBuffer {
6363
_sanityCheck(_hasNativeBuffer)
6464
return NativeBuffer(
6565
owner as? _ContiguousArrayStorageBase ?? _emptyArrayStorage)
6666
}
6767

68-
public var nativeOwner: AnyObject {
68+
internal var nativeOwner: AnyObject {
6969
_sanityCheck(_hasNativeBuffer, "Expect a native array")
7070
return owner
7171
}
@@ -76,7 +76,7 @@ struct _SliceBuffer<Element> : _ArrayBufferProtocol, RandomAccessCollection {
7676
/// - Precondition: This buffer is backed by a uniquely-referenced
7777
/// `_ContiguousArrayBuffer` and
7878
/// `insertCount <= numericCast(newValues.count)`.
79-
public mutating func replace<C>(
79+
internal mutating func replace<C>(
8080
subRange: Range<Int>,
8181
with insertCount: Int,
8282
elementsOf newValues: C
@@ -116,23 +116,23 @@ struct _SliceBuffer<Element> : _ArrayBufferProtocol, RandomAccessCollection {
116116
}
117117

118118
/// An object that keeps the elements stored in this buffer alive.
119-
public var owner: AnyObject
120-
public let subscriptBaseAddress: UnsafeMutablePointer<Element>
119+
internal var owner: AnyObject
120+
internal let subscriptBaseAddress: UnsafeMutablePointer<Element>
121121

122-
public var firstElementAddress: UnsafeMutablePointer<Element> {
122+
internal var firstElementAddress: UnsafeMutablePointer<Element> {
123123
return subscriptBaseAddress + startIndex
124124
}
125125

126-
public var firstElementAddressIfContiguous: UnsafeMutablePointer<Element>? {
126+
internal var firstElementAddressIfContiguous: UnsafeMutablePointer<Element>? {
127127
return firstElementAddress
128128
}
129129

130130
/// [63:1: 63-bit index][0: has a native buffer]
131-
var endIndexAndFlags: UInt
131+
internal var endIndexAndFlags: UInt
132132

133133
//===--- Non-essential bits ---------------------------------------------===//
134134

135-
public mutating func requestUniqueMutableBackingBuffer(
135+
internal mutating func requestUniqueMutableBackingBuffer(
136136
minimumCapacity: Int
137137
) -> NativeBuffer? {
138138
_invariantCheck()
@@ -161,18 +161,18 @@ struct _SliceBuffer<Element> : _ArrayBufferProtocol, RandomAccessCollection {
161161
return nil
162162
}
163163

164-
public mutating func isMutableAndUniquelyReferenced() -> Bool {
164+
internal mutating func isMutableAndUniquelyReferenced() -> Bool {
165165
return _hasNativeBuffer && isUniquelyReferenced()
166166
}
167167

168-
public mutating func isMutableAndUniquelyReferencedOrPinned() -> Bool {
168+
internal mutating func isMutableAndUniquelyReferencedOrPinned() -> Bool {
169169
return _hasNativeBuffer && isUniquelyReferencedOrPinned()
170170
}
171171

172172
/// If this buffer is backed by a `_ContiguousArrayBuffer`
173173
/// containing the same number of elements as `self`, return it.
174174
/// Otherwise, return `nil`.
175-
public func requestNativeBuffer() -> _ContiguousArrayBuffer<Element>? {
175+
internal func requestNativeBuffer() -> _ContiguousArrayBuffer<Element>? {
176176
_invariantCheck()
177177
if _fastPath(_hasNativeBuffer && nativeBuffer.count == count) {
178178
return nativeBuffer
@@ -181,7 +181,7 @@ struct _SliceBuffer<Element> : _ArrayBufferProtocol, RandomAccessCollection {
181181
}
182182

183183
@discardableResult
184-
public func _copyContents(
184+
internal func _copyContents(
185185
subRange bounds: Range<Int>,
186186
initializing target: UnsafeMutablePointer<Element>
187187
) -> UnsafeMutablePointer<Element> {
@@ -195,12 +195,11 @@ struct _SliceBuffer<Element> : _ArrayBufferProtocol, RandomAccessCollection {
195195
}
196196

197197
/// True, if the array is native and does not need a deferred type check.
198-
var arrayPropertyIsNativeTypeChecked: Bool {
198+
internal var arrayPropertyIsNativeTypeChecked: Bool {
199199
return _hasNativeBuffer
200200
}
201201

202-
public
203-
var count: Int {
202+
public var count: Int {
204203
get {
205204
return endIndex - startIndex
206205
}
@@ -221,7 +220,7 @@ struct _SliceBuffer<Element> : _ArrayBufferProtocol, RandomAccessCollection {
221220
index >= startIndex && index < endIndex, "Index out of bounds")
222221
}
223222

224-
public var capacity: Int {
223+
internal var capacity: Int {
225224
let count = self.count
226225
if _slowPath(!_hasNativeBuffer) {
227226
return count
@@ -234,16 +233,16 @@ struct _SliceBuffer<Element> : _ArrayBufferProtocol, RandomAccessCollection {
234233
return count
235234
}
236235

237-
mutating func isUniquelyReferenced() -> Bool {
236+
internal mutating func isUniquelyReferenced() -> Bool {
238237
return isUniquelyReferencedNonObjC(&owner)
239238
}
240239

241-
mutating func isUniquelyReferencedOrPinned() -> Bool {
240+
internal mutating func isUniquelyReferencedOrPinned() -> Bool {
242241
return isUniquelyReferencedOrPinnedNonObjC(&owner)
243242
}
244243

245244
@_versioned
246-
func getElement(_ i: Int) -> Element {
245+
internal func getElement(_ i: Int) -> Element {
247246
_sanityCheck(i >= startIndex, "negative slice index is out of range")
248247
_sanityCheck(i < endIndex, "slice index out of range")
249248
return subscriptBaseAddress[i]
@@ -305,8 +304,7 @@ struct _SliceBuffer<Element> : _ArrayBufferProtocol, RandomAccessCollection {
305304
//===--- misc -----------------------------------------------------------===//
306305
/// Call `body(p)`, where `p` is an `UnsafeBufferPointer` over the
307306
/// underlying contiguous storage.
308-
public
309-
func withUnsafeBufferPointer<R>(
307+
internal func withUnsafeBufferPointer<R>(
310308
_ body: @noescape (UnsafeBufferPointer<Element>) throws -> R
311309
) rethrows -> R {
312310
defer { _fixLifetime(self) }
@@ -316,8 +314,7 @@ struct _SliceBuffer<Element> : _ArrayBufferProtocol, RandomAccessCollection {
316314

317315
/// Call `body(p)`, where `p` is an `UnsafeMutableBufferPointer`
318316
/// over the underlying contiguous storage.
319-
public
320-
mutating func withUnsafeMutableBufferPointer<R>(
317+
internal mutating func withUnsafeMutableBufferPointer<R>(
321318
_ body: @noescape (UnsafeMutableBufferPointer<Element>) throws -> R
322319
) rethrows -> R {
323320
defer { _fixLifetime(self) }

0 commit comments

Comments
 (0)