32
32
// FIXME: rdar://18157434 - until this is fixed, this has to be fixed layout
33
33
// to avoid a hang in Foundation, which has the following setup:
34
34
// struct A { struct B { let x: UnsafeMutableBufferPointer<...> } let b: B }
35
- @_fixed_layout
35
+ @_fixed_layout // unsafe-performance
36
36
public struct Unsafe${ Mutable} BufferPointer< Element> {
37
37
38
38
@usableFromInline
@@ -49,12 +49,12 @@ public struct Unsafe${Mutable}BufferPointer<Element> {
49
49
extension UnsafeBufferPointer {
50
50
/// An iterator for the elements in the buffer referenced by an
51
51
/// `UnsafeBufferPointer` or `UnsafeMutableBufferPointer` instance.
52
- @_fixed_layout
52
+ @_fixed_layout // unsafe-performance
53
53
public struct Iterator {
54
54
@usableFromInline
55
55
internal var _position, _end: UnsafePointer < Element > ?
56
56
57
- @inlinable
57
+ @inlinable // unsafe-performance
58
58
public in it( _position: UnsafePointer < Element > ? , _end: UnsafePointer < Element > ? ) {
59
59
self . _position = _position
60
60
self . _end = _end
@@ -67,7 +67,7 @@ extension UnsafeBufferPointer.Iterator: IteratorProtocol {
67
67
/// exists.
68
68
///
69
69
/// Once `nil` has been returned, all subsequent calls return `nil`.
70
- @inlinable
70
+ @inlinable // unsafe-performance
71
71
public mutating func next( ) -> Element ? {
72
72
guard let start = _position else {
73
73
return nil
@@ -91,7 +91,7 @@ extension Unsafe${Mutable}BufferPointer: Sequence {
91
91
/// Returns an iterator over the elements of this buffer.
92
92
///
93
93
/// - Returns: An iterator over the elements of this buffer.
94
- @inlinable
94
+ @inlinable // unsafe-performance
95
95
public func makeIterator( ) -> Iterator {
96
96
guard let start = _position else {
97
97
return Iterator ( _position: nil , _end: nil )
@@ -104,7 +104,7 @@ extension Unsafe${Mutable}BufferPointer: Sequence {
104
104
///
105
105
/// - Returns: an iterator over any remaining elements of `self` and the
106
106
/// number of elements initialized.
107
- @inlinable // FIXME(sil-serialize-all)
107
+ @inlinable // unsafe-performance
108
108
public func _copyContents(
109
109
initializing destination: UnsafeMutableBufferPointer < Element >
110
110
) -> ( Iterator , UnsafeMutableBufferPointer < Element > . Index ) {
@@ -125,18 +125,18 @@ extension Unsafe${Mutable}BufferPointer: ${Mutable}Collection, RandomAccessColle
125
125
///
126
126
/// The `startIndex` property of an `Unsafe${Mutable}BufferPointer` instance
127
127
/// is always zero.
128
- @inlinable
128
+ @inlinable // unsafe-performance
129
129
public var startIndex : Int { return 0 }
130
130
131
131
/// The "past the end" position---that is, the position one greater than the
132
132
/// last valid subscript argument.
133
133
///
134
134
/// The `endIndex` property of an `Unsafe${Mutable}BufferPointer` instance is
135
135
/// always identical to `count`.
136
- @inlinable
136
+ @inlinable // unsafe-performance
137
137
public var endIndex : Int { return count }
138
138
139
- @inlinable
139
+ @inlinable // unsafe-performance
140
140
public func index( after i: Int ) -> Int {
141
141
// NOTE: this is a manual specialization of index movement for a Strideable
142
142
// index that is required for UnsafeBufferPointer performance. The
@@ -146,7 +146,7 @@ extension Unsafe${Mutable}BufferPointer: ${Mutable}Collection, RandomAccessColle
146
146
return i + 1
147
147
}
148
148
149
- @inlinable
149
+ @inlinable // unsafe-performance
150
150
public func formIndex( after i: inout Int ) {
151
151
// NOTE: this is a manual specialization of index movement for a Strideable
152
152
// index that is required for UnsafeBufferPointer performance. The
@@ -156,7 +156,7 @@ extension Unsafe${Mutable}BufferPointer: ${Mutable}Collection, RandomAccessColle
156
156
i += 1
157
157
}
158
158
159
- @inlinable
159
+ @inlinable // unsafe-performance
160
160
public func index( before i: Int ) -> Int {
161
161
// NOTE: this is a manual specialization of index movement for a Strideable
162
162
// index that is required for UnsafeBufferPointer performance. The
@@ -166,7 +166,7 @@ extension Unsafe${Mutable}BufferPointer: ${Mutable}Collection, RandomAccessColle
166
166
return i - 1
167
167
}
168
168
169
- @inlinable
169
+ @inlinable // unsafe-performance
170
170
public func formIndex( before i: inout Int ) {
171
171
// NOTE: this is a manual specialization of index movement for a Strideable
172
172
// index that is required for UnsafeBufferPointer performance. The
@@ -176,7 +176,7 @@ extension Unsafe${Mutable}BufferPointer: ${Mutable}Collection, RandomAccessColle
176
176
i -= 1
177
177
}
178
178
179
- @inlinable
179
+ @inlinable // unsafe-performance
180
180
public func index( _ i: Int , offsetBy n: Int ) -> Int {
181
181
// NOTE: this is a manual specialization of index movement for a Strideable
182
182
// index that is required for UnsafeBufferPointer performance. The
@@ -186,7 +186,7 @@ extension Unsafe${Mutable}BufferPointer: ${Mutable}Collection, RandomAccessColle
186
186
return i + n
187
187
}
188
188
189
- @inlinable
189
+ @inlinable // unsafe-performance
190
190
public func index( _ i: Int , offsetBy n: Int , limitedBy limit: Int ) -> Int ? {
191
191
// NOTE: this is a manual specialization of index movement for a Strideable
192
192
// index that is required for UnsafeBufferPointer performance. The
@@ -200,7 +200,7 @@ extension Unsafe${Mutable}BufferPointer: ${Mutable}Collection, RandomAccessColle
200
200
return i + n
201
201
}
202
202
203
- @inlinable
203
+ @inlinable // unsafe-performance
204
204
public func distance( from start: Int , to end: Int ) -> Int {
205
205
// NOTE: this is a manual specialization of index movement for a Strideable
206
206
// index that is required for UnsafeBufferPointer performance. The
@@ -210,21 +210,21 @@ extension Unsafe${Mutable}BufferPointer: ${Mutable}Collection, RandomAccessColle
210
210
return end - start
211
211
}
212
212
213
- @inlinable
213
+ @inlinable // unsafe-performance
214
214
public func _failEarlyRangeCheck( _ index: Int , bounds: Range < Int > ) {
215
215
// NOTE: In release mode, this method is a no-op for performance reasons.
216
216
_debugPrecondition ( index >= bounds. lowerBound)
217
217
_debugPrecondition ( index < bounds. upperBound)
218
218
}
219
219
220
- @inlinable
220
+ @inlinable // unsafe-performance
221
221
public func _failEarlyRangeCheck( _ range: Range < Int > , bounds: Range < Int > ) {
222
222
// NOTE: In release mode, this method is a no-op for performance reasons.
223
223
_debugPrecondition ( range. lowerBound >= bounds. lowerBound)
224
224
_debugPrecondition ( range. upperBound <= bounds. upperBound)
225
225
}
226
226
227
- @inlinable
227
+ @inlinable // unsafe-performance
228
228
public var indices : Indices {
229
229
return startIndex..< endIndex
230
230
}
@@ -265,7 +265,7 @@ extension Unsafe${Mutable}BufferPointer: ${Mutable}Collection, RandomAccessColle
265
265
///
266
266
/// - Parameter i: The position of the element to access. `i` must be in the
267
267
/// range `0..<count`.
268
- @inlinable
268
+ @inlinable // unsafe-performance
269
269
public subscript( i: Int) -> Element {
270
270
get {
271
271
_debugPrecondition ( i >= 0 )
@@ -318,7 +318,7 @@ extension Unsafe${Mutable}BufferPointer: ${Mutable}Collection, RandomAccessColle
318
318
///
319
319
/// - Parameter bounds: A range of the buffer's indices. The bounds of
320
320
/// the range must be valid indices of the buffer.
321
- @inlinable
321
+ @inlinable // unsafe-performance
322
322
public subscript( bounds: Range < Int > )
323
323
-> Slice< Unsafe${ Mutable} BufferPointer< Element>>
324
324
{
@@ -354,7 +354,7 @@ extension Unsafe${Mutable}BufferPointer: ${Mutable}Collection, RandomAccessColle
354
354
/// - Parameters:
355
355
/// - i: The index of the first value to swap.
356
356
/// - j: The index of the second value to swap.
357
- @inlinable
357
+ @inlinable // unsafe-performance
358
358
public func swapAt( _ i: Int, _ j: Int) {
359
359
guard i != j else { return }
360
360
_debugPrecondition ( i >= 0 && j >= 0 )
@@ -379,7 +379,7 @@ extension Unsafe${Mutable}BufferPointer {
379
379
/// `MemoryLayout<Element>.alignment`.
380
380
/// - count: The number of instances in the buffer. `count` must not be
381
381
/// negative.
382
- @inlinable
382
+ @inlinable // unsafe-performance
383
383
public init( start: Unsafe ${ Mutable} Pointer < Element > ? , count: Int) {
384
384
_precondition (
385
385
count >= 0 , " Unsafe${Mutable}BufferPointer with negative count " )
@@ -390,7 +390,7 @@ extension Unsafe${Mutable}BufferPointer {
390
390
self . count = count
391
391
}
392
392
393
- @inlinable
393
+ @inlinable // unsafe-performance
394
394
public init( _empty: ( ) ) {
395
395
_position = nil
396
396
count = 0
@@ -402,7 +402,7 @@ extension Unsafe${Mutable}BufferPointer {
402
402
/// given immutable buffer pointer.
403
403
///
404
404
/// - Parameter other: The immutable buffer pointer to convert.
405
- @inlinable
405
+ @inlinable // unsafe-performance
406
406
public init( mutating other: UnsafeBufferPointer< Element> ) {
407
407
_position = UnsafeMutablePointer < Element > ( mutating: other. _position)
408
408
count = other. count
@@ -414,7 +414,7 @@ extension Unsafe${Mutable}BufferPointer {
414
414
/// given mutable buffer pointer.
415
415
///
416
416
/// - Parameter other: The mutable buffer pointer to convert.
417
- @inlinable
417
+ @inlinable // unsafe-performance
418
418
public init( _ other: UnsafeMutableBufferPointer< Element> ) {
419
419
_position = UnsafePointer < Element > ( other. _position)
420
420
count = other. count
@@ -443,7 +443,7 @@ extension Unsafe${Mutable}BufferPointer {
443
443
/// - `rebased.count == slice.count`
444
444
///
445
445
/// - Parameter slice: The buffer slice to rebase.
446
- @inlinable
446
+ @inlinable // unsafe-performance
447
447
public init( rebasing slice: Slice< UnsafeBufferPointer< Element>>) {
448
448
self . init ( start: slice. base. baseAddress! + slice. startIndex,
449
449
count: slice. count)
@@ -470,7 +470,7 @@ extension Unsafe${Mutable}BufferPointer {
470
470
/// - `rebased.count == slice.count`
471
471
///
472
472
/// - Parameter slice: The buffer slice to rebase.
473
- @inlinable
473
+ @inlinable // unsafe-performance
474
474
public init( rebasing slice: Slice < UnsafeMutableBufferPointer < Element > > ) {
475
475
self . init (
476
476
start: slice. base. baseAddress! + slice. startIndex,
@@ -485,7 +485,7 @@ extension Unsafe${Mutable}BufferPointer {
485
485
/// `nil`, this function does nothing. Otherwise, the memory must not be initialized
486
486
/// or `Pointee` must be a trivial type. This buffer pointer's `count` must
487
487
/// be equal to the originally allocated size of the memory block.
488
- @inlinable
488
+ @inlinable // unsafe-performance
489
489
public func deallocate( ) {
490
490
_position? . deallocate ( )
491
491
}
@@ -513,7 +513,7 @@ extension Unsafe${Mutable}BufferPointer {
513
513
///
514
514
/// - Parameter count: The amount of memory to allocate, counted in instances
515
515
/// of `Element`.
516
- @inlinable
516
+ @inlinable // unsafe-performance
517
517
public static func allocate( capacity count: Int)
518
518
- > UnsafeMutableBufferPointer< Element> {
519
519
let size = MemoryLayout < Element > . stride * count
@@ -531,7 +531,7 @@ extension Unsafe${Mutable}BufferPointer {
531
531
///
532
532
/// - Parameters:
533
533
/// - repeatedValue: The instance to initialize this buffer's memory with.
534
- @inlinable
534
+ @inlinable // unsafe-performance
535
535
public func initialize( repeating repeatedValue: Element) {
536
536
guard let dstBase = _position else {
537
537
return
@@ -551,7 +551,7 @@ extension Unsafe${Mutable}BufferPointer {
551
551
/// Warning: All buffer elements must be initialized before calling this.
552
552
/// Assigning to part of the buffer must be done using the `assign(repeating:count:)``
553
553
/// method on the buffer’s `baseAddress`.
554
- @inlinable
554
+ @inlinable // unsafe-performance
555
555
public func assign( repeating repeatedValue: Element) {
556
556
guard let dstBase = _position else {
557
557
return
@@ -600,7 +600,7 @@ extension Unsafe${Mutable}BufferPointer {
600
600
/// value is also used as the return value for the `withMemoryRebound(to:_:)`
601
601
/// method.
602
602
/// - Returns: The return value, if any, of the `body` closure parameter.
603
- @inlinable
603
+ @inlinable // unsafe-performance
604
604
public func withMemoryRebound< T, Result> (
605
605
to type: T . Type, _ body: ( ${ Self} < T> ) throws -> Result
606
606
) rethrows -> Result {
@@ -623,7 +623,7 @@ extension Unsafe${Mutable}BufferPointer {
623
623
///
624
624
/// If the `baseAddress` of this buffer is `nil`, the count is zero. However,
625
625
/// a buffer can have a `count` of zero even with a non-`nil` base address.
626
- @inlinable
626
+ @inlinable // unsafe-performance
627
627
public var baseAddress: Unsafe${ Mutable} Pointer< Element>? {
628
628
return _position
629
629
}
@@ -660,7 +660,7 @@ extension UnsafeMutableBufferPointer {
660
660
/// - Returns: An iterator to any elements of `source` that didn't fit in the
661
661
/// buffer, and an index to the point in the buffer one past the last
662
662
/// element written.
663
- @inlinable
663
+ @inlinable // unsafe-performance
664
664
public func initialize< S: Sequence > ( from source: S) - > ( S . Iterator, Index)
665
665
where S. Element == Element {
666
666
return source. _copyContents ( initializing: self )
0 commit comments