14
14
public // @testable
15
15
struct _SliceBuffer < Element> : _ArrayBufferProtocol , RandomAccessCollection {
16
16
internal typealias NativeStorage = _ContiguousArrayStorage < Element >
17
- public typealias NativeBuffer = _ContiguousArrayBuffer < Element >
17
+ internal typealias NativeBuffer = _ContiguousArrayBuffer < Element >
18
18
19
- init (
19
+ internal init (
20
20
owner: AnyObject , subscriptBaseAddress: UnsafeMutablePointer < Element > ,
21
21
indices: Range < Int > , hasNativeBuffer: Bool
22
22
) {
@@ -28,7 +28,7 @@ struct _SliceBuffer<Element> : _ArrayBufferProtocol, RandomAccessCollection {
28
28
_invariantCheck ( )
29
29
}
30
30
31
- public init ( ) {
31
+ internal init ( ) {
32
32
let empty = _ContiguousArrayBuffer < Element > ( )
33
33
self . owner = empty. owner
34
34
self . subscriptBaseAddress = empty. firstElementAddress
@@ -37,7 +37,7 @@ struct _SliceBuffer<Element> : _ArrayBufferProtocol, RandomAccessCollection {
37
37
_invariantCheck ( )
38
38
}
39
39
40
- public init ( _buffer buffer: NativeBuffer , shiftedToStartIndex: Int ) {
40
+ internal init ( _buffer buffer: NativeBuffer , shiftedToStartIndex: Int ) {
41
41
let shift = buffer. startIndex - shiftedToStartIndex
42
42
self . init (
43
43
owner: buffer. owner,
@@ -46,7 +46,7 @@ struct _SliceBuffer<Element> : _ArrayBufferProtocol, RandomAccessCollection {
46
46
hasNativeBuffer: true )
47
47
}
48
48
49
- func _invariantCheck( ) {
49
+ internal func _invariantCheck( ) {
50
50
let isNative = _hasNativeBuffer
51
51
let isNativeStorage : Bool = ( owner as? _ContiguousArrayStorageBase ) != nil
52
52
_sanityCheck ( isNativeStorage == isNative)
@@ -55,17 +55,17 @@ struct _SliceBuffer<Element> : _ArrayBufferProtocol, RandomAccessCollection {
55
55
}
56
56
}
57
57
58
- var _hasNativeBuffer : Bool {
58
+ internal var _hasNativeBuffer : Bool {
59
59
return ( endIndexAndFlags & 1 ) != 0
60
60
}
61
61
62
- var nativeBuffer : NativeBuffer {
62
+ internal var nativeBuffer : NativeBuffer {
63
63
_sanityCheck ( _hasNativeBuffer)
64
64
return NativeBuffer (
65
65
owner as? _ContiguousArrayStorageBase ?? _emptyArrayStorage)
66
66
}
67
67
68
- public var nativeOwner : AnyObject {
68
+ internal var nativeOwner : AnyObject {
69
69
_sanityCheck ( _hasNativeBuffer, " Expect a native array " )
70
70
return owner
71
71
}
@@ -76,7 +76,7 @@ struct _SliceBuffer<Element> : _ArrayBufferProtocol, RandomAccessCollection {
76
76
/// - Precondition: This buffer is backed by a uniquely-referenced
77
77
/// `_ContiguousArrayBuffer` and
78
78
/// `insertCount <= numericCast(newValues.count)`.
79
- public mutating func replace< C> (
79
+ internal mutating func replace< C> (
80
80
subRange: Range < Int > ,
81
81
with insertCount: Int ,
82
82
elementsOf newValues: C
@@ -116,23 +116,23 @@ struct _SliceBuffer<Element> : _ArrayBufferProtocol, RandomAccessCollection {
116
116
}
117
117
118
118
/// 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 >
121
121
122
- public var firstElementAddress : UnsafeMutablePointer < Element > {
122
+ internal var firstElementAddress : UnsafeMutablePointer < Element > {
123
123
return subscriptBaseAddress + startIndex
124
124
}
125
125
126
- public var firstElementAddressIfContiguous : UnsafeMutablePointer < Element > ? {
126
+ internal var firstElementAddressIfContiguous : UnsafeMutablePointer < Element > ? {
127
127
return firstElementAddress
128
128
}
129
129
130
130
/// [63:1: 63-bit index][0: has a native buffer]
131
- var endIndexAndFlags : UInt
131
+ internal var endIndexAndFlags : UInt
132
132
133
133
//===--- Non-essential bits ---------------------------------------------===//
134
134
135
- public mutating func requestUniqueMutableBackingBuffer(
135
+ internal mutating func requestUniqueMutableBackingBuffer(
136
136
minimumCapacity: Int
137
137
) -> NativeBuffer ? {
138
138
_invariantCheck ( )
@@ -161,18 +161,18 @@ struct _SliceBuffer<Element> : _ArrayBufferProtocol, RandomAccessCollection {
161
161
return nil
162
162
}
163
163
164
- public mutating func isMutableAndUniquelyReferenced( ) -> Bool {
164
+ internal mutating func isMutableAndUniquelyReferenced( ) -> Bool {
165
165
return _hasNativeBuffer && isUniquelyReferenced ( )
166
166
}
167
167
168
- public mutating func isMutableAndUniquelyReferencedOrPinned( ) -> Bool {
168
+ internal mutating func isMutableAndUniquelyReferencedOrPinned( ) -> Bool {
169
169
return _hasNativeBuffer && isUniquelyReferencedOrPinned ( )
170
170
}
171
171
172
172
/// If this buffer is backed by a `_ContiguousArrayBuffer`
173
173
/// containing the same number of elements as `self`, return it.
174
174
/// Otherwise, return `nil`.
175
- public func requestNativeBuffer( ) -> _ContiguousArrayBuffer < Element > ? {
175
+ internal func requestNativeBuffer( ) -> _ContiguousArrayBuffer < Element > ? {
176
176
_invariantCheck ( )
177
177
if _fastPath ( _hasNativeBuffer && nativeBuffer. count == count) {
178
178
return nativeBuffer
@@ -181,7 +181,7 @@ struct _SliceBuffer<Element> : _ArrayBufferProtocol, RandomAccessCollection {
181
181
}
182
182
183
183
@discardableResult
184
- public func _copyContents(
184
+ internal func _copyContents(
185
185
subRange bounds: Range < Int > ,
186
186
initializing target: UnsafeMutablePointer < Element >
187
187
) -> UnsafeMutablePointer < Element > {
@@ -195,12 +195,11 @@ struct _SliceBuffer<Element> : _ArrayBufferProtocol, RandomAccessCollection {
195
195
}
196
196
197
197
/// True, if the array is native and does not need a deferred type check.
198
- var arrayPropertyIsNativeTypeChecked : Bool {
198
+ internal var arrayPropertyIsNativeTypeChecked : Bool {
199
199
return _hasNativeBuffer
200
200
}
201
201
202
- public
203
- var count : Int {
202
+ public var count : Int {
204
203
get {
205
204
return endIndex - startIndex
206
205
}
@@ -221,7 +220,7 @@ struct _SliceBuffer<Element> : _ArrayBufferProtocol, RandomAccessCollection {
221
220
index >= startIndex && index < endIndex, " Index out of bounds " )
222
221
}
223
222
224
- public var capacity : Int {
223
+ internal var capacity : Int {
225
224
let count = self . count
226
225
if _slowPath ( !_hasNativeBuffer) {
227
226
return count
@@ -234,16 +233,16 @@ struct _SliceBuffer<Element> : _ArrayBufferProtocol, RandomAccessCollection {
234
233
return count
235
234
}
236
235
237
- mutating func isUniquelyReferenced( ) -> Bool {
236
+ internal mutating func isUniquelyReferenced( ) -> Bool {
238
237
return isUniquelyReferencedNonObjC ( & owner)
239
238
}
240
239
241
- mutating func isUniquelyReferencedOrPinned( ) -> Bool {
240
+ internal mutating func isUniquelyReferencedOrPinned( ) -> Bool {
242
241
return isUniquelyReferencedOrPinnedNonObjC ( & owner)
243
242
}
244
243
245
244
@_versioned
246
- func getElement( _ i: Int ) -> Element {
245
+ internal func getElement( _ i: Int ) -> Element {
247
246
_sanityCheck ( i >= startIndex, " negative slice index is out of range " )
248
247
_sanityCheck ( i < endIndex, " slice index out of range " )
249
248
return subscriptBaseAddress [ i]
@@ -305,8 +304,7 @@ struct _SliceBuffer<Element> : _ArrayBufferProtocol, RandomAccessCollection {
305
304
//===--- misc -----------------------------------------------------------===//
306
305
/// Call `body(p)`, where `p` is an `UnsafeBufferPointer` over the
307
306
/// underlying contiguous storage.
308
- public
309
- func withUnsafeBufferPointer< R> (
307
+ internal func withUnsafeBufferPointer< R> (
310
308
_ body: @noescape ( UnsafeBufferPointer < Element > ) throws -> R
311
309
) rethrows -> R {
312
310
defer { _fixLifetime ( self ) }
@@ -316,8 +314,7 @@ struct _SliceBuffer<Element> : _ArrayBufferProtocol, RandomAccessCollection {
316
314
317
315
/// Call `body(p)`, where `p` is an `UnsafeMutableBufferPointer`
318
316
/// over the underlying contiguous storage.
319
- public
320
- mutating func withUnsafeMutableBufferPointer< R> (
317
+ internal mutating func withUnsafeMutableBufferPointer< R> (
321
318
_ body: @noescape ( UnsafeMutableBufferPointer < Element > ) throws -> R
322
319
) rethrows -> R {
323
320
defer { _fixLifetime ( self ) }
0 commit comments