15
15
@frozen
16
16
public struct Slab < let count: Int , Element: ~ Copyable> : ~ Copyable {
17
17
@usableFromInline
18
- let storage : Builtin . FixedArray < count , Element >
18
+ internal let _storage : Builtin . FixedArray < count , Element >
19
19
}
20
20
21
21
@available ( SwiftStdlib 6 . 1 , * )
@@ -37,23 +37,23 @@ extension Slab where Element: ~Copyable {
37
37
@available ( SwiftStdlib 6 . 1 , * )
38
38
@_alwaysEmitIntoClient
39
39
@_transparent
40
- var address : UnsafePointer < Element > {
40
+ internal var _address : UnsafePointer < Element > {
41
41
UnsafePointer < Element > ( Builtin . unprotectedAddressOfBorrow ( self ) )
42
42
}
43
43
44
44
/// Returns a buffer pointer over the entire vector.
45
45
@available ( SwiftStdlib 6 . 1 , * )
46
46
@_alwaysEmitIntoClient
47
47
@_transparent
48
- var buffer : UnsafeBufferPointer < Element > {
49
- UnsafeBufferPointer < Element > ( start: address , count: count)
48
+ internal var _buffer : UnsafeBufferPointer < Element > {
49
+ UnsafeBufferPointer < Element > ( start: _address , count: count)
50
50
}
51
51
52
52
/// Returns a mutable pointer to the first element in the vector.
53
53
@available ( SwiftStdlib 6 . 1 , * )
54
54
@_alwaysEmitIntoClient
55
55
@_transparent
56
- var mutableAddress : UnsafeMutablePointer < Element > {
56
+ internal var _mutableAddress : UnsafeMutablePointer < Element > {
57
57
mutating get {
58
58
UnsafeMutablePointer < Element > ( Builtin . unprotectedAddressOf ( & self ) )
59
59
}
@@ -63,9 +63,9 @@ extension Slab where Element: ~Copyable {
63
63
@available ( SwiftStdlib 6 . 1 , * )
64
64
@_alwaysEmitIntoClient
65
65
@_transparent
66
- var mutableBuffer : UnsafeMutableBufferPointer < Element > {
66
+ internal var _mutableBuffer : UnsafeMutableBufferPointer < Element > {
67
67
mutating get {
68
- UnsafeMutableBufferPointer < Element > ( start: mutableAddress , count: count)
68
+ UnsafeMutableBufferPointer < Element > ( start: _mutableAddress , count: count)
69
69
}
70
70
}
71
71
@@ -74,7 +74,7 @@ extension Slab where Element: ~Copyable {
74
74
@available ( SwiftStdlib 6 . 1 , * )
75
75
@_alwaysEmitIntoClient
76
76
@_transparent
77
- static func _initializationBuffer(
77
+ internal static func _initializationBuffer(
78
78
start: Builtin . RawPointer
79
79
) -> UnsafeMutableBufferPointer < Element > {
80
80
UnsafeMutableBufferPointer < Element > (
@@ -197,7 +197,7 @@ extension Slab where Element: Copyable {
197
197
198
198
@available ( SwiftStdlib 6 . 1 , * )
199
199
extension Slab where Element: ~ Copyable {
200
- /// A type representing the collection 's elements.
200
+ /// The type of the container 's elements.
201
201
@available ( SwiftStdlib 6 . 1 , * )
202
202
public typealias Element = Element
203
203
@@ -292,7 +292,7 @@ extension Slab where Element: ~Copyable {
292
292
@_alwaysEmitIntoClient
293
293
@_transparent
294
294
public borrowing func index( after i: Int ) -> Int {
295
- i + 1
295
+ i & + 1
296
296
}
297
297
298
298
/// Returns the position immediately before the given index.
@@ -304,7 +304,7 @@ extension Slab where Element: ~Copyable {
304
304
@_alwaysEmitIntoClient
305
305
@_transparent
306
306
public borrowing func index( before i: Int ) -> Int {
307
- i - 1
307
+ i & - 1
308
308
}
309
309
310
310
/// Accesses the element at the specified position.
@@ -334,14 +334,14 @@ extension Slab where Element: ~Copyable {
334
334
unsafeAddress {
335
335
_precondition ( indices. contains ( i) , " Index out of bounds " )
336
336
337
- return address + i
337
+ return _address + i
338
338
}
339
339
340
340
@_transparent
341
341
unsafeMutableAddress {
342
342
_precondition ( indices. contains ( i) , " Index out of bounds " )
343
343
344
- return mutableAddress + i
344
+ return _mutableAddress + i
345
345
}
346
346
}
347
347
}
@@ -369,14 +369,17 @@ extension Slab where Element: ~Copyable {
369
369
_ i: Int ,
370
370
_ j: Int
371
371
) {
372
- guard i != j, indices . contains ( i ) , indices . contains ( j ) else {
372
+ guard i != j else {
373
373
return
374
374
}
375
375
376
- let ithElement = mutableBuffer. moveElement ( from: i)
377
- let jthElement = mutableBuffer. moveElement ( from: j)
378
- mutableBuffer. initializeElement ( at: i, to: jthElement)
379
- mutableBuffer. initializeElement ( at: j, to: ithElement)
376
+ _precondition ( indices. contains ( i) , " Index out of bounds " )
377
+ _precondition ( indices. contains ( j) , " Index out of bounds " )
378
+
379
+ let ithElement = _mutableBuffer. moveElement ( from: i)
380
+ let jthElement = _mutableBuffer. moveElement ( from: j)
381
+ _mutableBuffer. initializeElement ( at: i, to: jthElement)
382
+ _mutableBuffer. initializeElement ( at: j, to: ithElement)
380
383
}
381
384
}
382
385
@@ -422,10 +425,10 @@ extension Slab where Element: ~Copyable {
422
425
@available ( SwiftStdlib 6 . 1 , * )
423
426
@_alwaysEmitIntoClient
424
427
@_transparent
425
- public borrowing func _withUnsafeBufferPointer< Result, E: Error > (
428
+ public borrowing func _withUnsafeBufferPointer< Result: ~ Copyable , E: Error > (
426
429
_ body: ( UnsafeBufferPointer < Element > ) throws ( E ) -> Result
427
430
) throws ( E) -> Result {
428
- try body ( buffer )
431
+ try body ( _buffer )
429
432
}
430
433
431
434
/// Calls the given closure with a pointer to the vector's mutable contiguous
@@ -471,9 +474,9 @@ extension Slab where Element: ~Copyable {
471
474
@available ( SwiftStdlib 6 . 1 , * )
472
475
@_alwaysEmitIntoClient
473
476
@_transparent
474
- public mutating func _withUnsafeMutableBufferPointer< Result, E: Error > (
477
+ public mutating func _withUnsafeMutableBufferPointer< Result: ~ Copyable , E: Error > (
475
478
_ body: ( UnsafeMutableBufferPointer < Element > ) throws ( E ) -> Result
476
479
) throws ( E) -> Result {
477
- try body ( mutableBuffer )
480
+ try body ( _mutableBuffer )
478
481
}
479
482
}
0 commit comments