1515@frozen
1616public struct Slab < let count: Int , Element: ~ Copyable> : ~ Copyable {
1717 @usableFromInline
18- let storage : Builtin . FixedArray < count , Element >
18+ internal let _storage : Builtin . FixedArray < count , Element >
1919}
2020
2121@available ( SwiftStdlib 6 . 1 , * )
@@ -37,23 +37,23 @@ extension Slab where Element: ~Copyable {
3737 @available ( SwiftStdlib 6 . 1 , * )
3838 @_alwaysEmitIntoClient
3939 @_transparent
40- var address : UnsafePointer < Element > {
40+ internal var _address : UnsafePointer < Element > {
4141 UnsafePointer < Element > ( Builtin . unprotectedAddressOfBorrow ( self ) )
4242 }
4343
4444 /// Returns a buffer pointer over the entire vector.
4545 @available ( SwiftStdlib 6 . 1 , * )
4646 @_alwaysEmitIntoClient
4747 @_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)
5050 }
5151
5252 /// Returns a mutable pointer to the first element in the vector.
5353 @available ( SwiftStdlib 6 . 1 , * )
5454 @_alwaysEmitIntoClient
5555 @_transparent
56- var mutableAddress : UnsafeMutablePointer < Element > {
56+ internal var _mutableAddress : UnsafeMutablePointer < Element > {
5757 mutating get {
5858 UnsafeMutablePointer < Element > ( Builtin . unprotectedAddressOf ( & self ) )
5959 }
@@ -63,9 +63,9 @@ extension Slab where Element: ~Copyable {
6363 @available ( SwiftStdlib 6 . 1 , * )
6464 @_alwaysEmitIntoClient
6565 @_transparent
66- var mutableBuffer : UnsafeMutableBufferPointer < Element > {
66+ internal var _mutableBuffer : UnsafeMutableBufferPointer < Element > {
6767 mutating get {
68- UnsafeMutableBufferPointer < Element > ( start: mutableAddress , count: count)
68+ UnsafeMutableBufferPointer < Element > ( start: _mutableAddress , count: count)
6969 }
7070 }
7171
@@ -74,7 +74,7 @@ extension Slab where Element: ~Copyable {
7474 @available ( SwiftStdlib 6 . 1 , * )
7575 @_alwaysEmitIntoClient
7676 @_transparent
77- static func _initializationBuffer(
77+ internal static func _initializationBuffer(
7878 start: Builtin . RawPointer
7979 ) -> UnsafeMutableBufferPointer < Element > {
8080 UnsafeMutableBufferPointer < Element > (
@@ -197,7 +197,7 @@ extension Slab where Element: Copyable {
197197
198198@available ( SwiftStdlib 6 . 1 , * )
199199extension Slab where Element: ~ Copyable {
200- /// A type representing the collection 's elements.
200+ /// The type of the container 's elements.
201201 @available ( SwiftStdlib 6 . 1 , * )
202202 public typealias Element = Element
203203
@@ -292,7 +292,7 @@ extension Slab where Element: ~Copyable {
292292 @_alwaysEmitIntoClient
293293 @_transparent
294294 public borrowing func index( after i: Int ) -> Int {
295- i + 1
295+ i & + 1
296296 }
297297
298298 /// Returns the position immediately before the given index.
@@ -304,7 +304,7 @@ extension Slab where Element: ~Copyable {
304304 @_alwaysEmitIntoClient
305305 @_transparent
306306 public borrowing func index( before i: Int ) -> Int {
307- i - 1
307+ i & - 1
308308 }
309309
310310 /// Accesses the element at the specified position.
@@ -334,14 +334,14 @@ extension Slab where Element: ~Copyable {
334334 unsafeAddress {
335335 _precondition ( indices. contains ( i) , " Index out of bounds " )
336336
337- return address + i
337+ return _address + i
338338 }
339339
340340 @_transparent
341341 unsafeMutableAddress {
342342 _precondition ( indices. contains ( i) , " Index out of bounds " )
343343
344- return mutableAddress + i
344+ return _mutableAddress + i
345345 }
346346 }
347347}
@@ -369,14 +369,17 @@ extension Slab where Element: ~Copyable {
369369 _ i: Int ,
370370 _ j: Int
371371 ) {
372- guard i != j, indices . contains ( i ) , indices . contains ( j ) else {
372+ guard i != j else {
373373 return
374374 }
375375
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)
380383 }
381384}
382385
@@ -422,10 +425,10 @@ extension Slab where Element: ~Copyable {
422425 @available ( SwiftStdlib 6 . 1 , * )
423426 @_alwaysEmitIntoClient
424427 @_transparent
425- public borrowing func _withUnsafeBufferPointer< Result, E: Error > (
428+ public borrowing func _withUnsafeBufferPointer< Result: ~ Copyable , E: Error > (
426429 _ body: ( UnsafeBufferPointer < Element > ) throws ( E ) -> Result
427430 ) throws ( E) -> Result {
428- try body ( buffer )
431+ try body ( _buffer )
429432 }
430433
431434 /// Calls the given closure with a pointer to the vector's mutable contiguous
@@ -471,9 +474,9 @@ extension Slab where Element: ~Copyable {
471474 @available ( SwiftStdlib 6 . 1 , * )
472475 @_alwaysEmitIntoClient
473476 @_transparent
474- public mutating func _withUnsafeMutableBufferPointer< Result, E: Error > (
477+ public mutating func _withUnsafeMutableBufferPointer< Result: ~ Copyable , E: Error > (
475478 _ body: ( UnsafeMutableBufferPointer < Element > ) throws ( E ) -> Result
476479 ) throws ( E) -> Result {
477- try body ( mutableBuffer )
480+ try body ( _mutableBuffer )
478481 }
479482}
0 commit comments