Skip to content

Commit eeb6721

Browse files
committed
Inlineable: unsafe performance
1 parent c6b41a5 commit eeb6721

File tree

3 files changed

+52
-52
lines changed

3 files changed

+52
-52
lines changed

stdlib/public/core/Builtin.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func _canBeClass<T>(_: T.Type) -> Int8 {
7878
/// - type: The type to cast `x` to. `type` and the type of `x` must have the
7979
/// same size of memory representation and compatible memory layout.
8080
/// - Returns: A new instance of type `U`, cast from `x`.
81-
@inlinable // FIXME(sil-serialize-all)
81+
@inlinable // unsafe-performance
8282
@_transparent
8383
public func unsafeBitCast<T, U>(_ x: T, to type: U.Type) -> U {
8484
_precondition(MemoryLayout<T>.size == MemoryLayout<U>.size,

stdlib/public/core/UnsafeBufferPointer.swift.gyb

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
// FIXME: rdar://18157434 - until this is fixed, this has to be fixed layout
3333
// to avoid a hang in Foundation, which has the following setup:
3434
// struct A { struct B { let x: UnsafeMutableBufferPointer<...> } let b: B }
35-
@_fixed_layout
35+
@_fixed_layout // unsafe-performance
3636
public struct Unsafe${Mutable}BufferPointer<Element> {
3737

3838
@usableFromInline
@@ -49,12 +49,12 @@ public struct Unsafe${Mutable}BufferPointer<Element> {
4949
extension UnsafeBufferPointer {
5050
/// An iterator for the elements in the buffer referenced by an
5151
/// `UnsafeBufferPointer` or `UnsafeMutableBufferPointer` instance.
52-
@_fixed_layout
52+
@_fixed_layout // unsafe-performance
5353
public struct Iterator {
5454
@usableFromInline
5555
internal var _position, _end: UnsafePointer<Element>?
5656

57-
@inlinable
57+
@inlinable // unsafe-performance
5858
public init(_position: UnsafePointer<Element>?, _end: UnsafePointer<Element>?) {
5959
self._position = _position
6060
self._end = _end
@@ -67,7 +67,7 @@ extension UnsafeBufferPointer.Iterator: IteratorProtocol {
6767
/// exists.
6868
///
6969
/// Once `nil` has been returned, all subsequent calls return `nil`.
70-
@inlinable
70+
@inlinable // unsafe-performance
7171
public mutating func next() -> Element? {
7272
guard let start = _position else {
7373
return nil
@@ -91,7 +91,7 @@ extension Unsafe${Mutable}BufferPointer: Sequence {
9191
/// Returns an iterator over the elements of this buffer.
9292
///
9393
/// - Returns: An iterator over the elements of this buffer.
94-
@inlinable
94+
@inlinable // unsafe-performance
9595
public func makeIterator() -> Iterator {
9696
guard let start = _position else {
9797
return Iterator(_position: nil, _end: nil)
@@ -104,7 +104,7 @@ extension Unsafe${Mutable}BufferPointer: Sequence {
104104
///
105105
/// - Returns: an iterator over any remaining elements of `self` and the
106106
/// number of elements initialized.
107-
@inlinable // FIXME(sil-serialize-all)
107+
@inlinable // unsafe-performance
108108
public func _copyContents(
109109
initializing destination: UnsafeMutableBufferPointer<Element>
110110
) -> (Iterator, UnsafeMutableBufferPointer<Element>.Index) {
@@ -125,18 +125,18 @@ extension Unsafe${Mutable}BufferPointer: ${Mutable}Collection, RandomAccessColle
125125
///
126126
/// The `startIndex` property of an `Unsafe${Mutable}BufferPointer` instance
127127
/// is always zero.
128-
@inlinable
128+
@inlinable // unsafe-performance
129129
public var startIndex: Int { return 0 }
130130

131131
/// The "past the end" position---that is, the position one greater than the
132132
/// last valid subscript argument.
133133
///
134134
/// The `endIndex` property of an `Unsafe${Mutable}BufferPointer` instance is
135135
/// always identical to `count`.
136-
@inlinable
136+
@inlinable // unsafe-performance
137137
public var endIndex: Int { return count }
138138

139-
@inlinable
139+
@inlinable // unsafe-performance
140140
public func index(after i: Int) -> Int {
141141
// NOTE: this is a manual specialization of index movement for a Strideable
142142
// index that is required for UnsafeBufferPointer performance. The
@@ -146,7 +146,7 @@ extension Unsafe${Mutable}BufferPointer: ${Mutable}Collection, RandomAccessColle
146146
return i + 1
147147
}
148148

149-
@inlinable
149+
@inlinable // unsafe-performance
150150
public func formIndex(after i: inout Int) {
151151
// NOTE: this is a manual specialization of index movement for a Strideable
152152
// index that is required for UnsafeBufferPointer performance. The
@@ -156,7 +156,7 @@ extension Unsafe${Mutable}BufferPointer: ${Mutable}Collection, RandomAccessColle
156156
i += 1
157157
}
158158

159-
@inlinable
159+
@inlinable // unsafe-performance
160160
public func index(before i: Int) -> Int {
161161
// NOTE: this is a manual specialization of index movement for a Strideable
162162
// index that is required for UnsafeBufferPointer performance. The
@@ -166,7 +166,7 @@ extension Unsafe${Mutable}BufferPointer: ${Mutable}Collection, RandomAccessColle
166166
return i - 1
167167
}
168168

169-
@inlinable
169+
@inlinable // unsafe-performance
170170
public func formIndex(before i: inout Int) {
171171
// NOTE: this is a manual specialization of index movement for a Strideable
172172
// index that is required for UnsafeBufferPointer performance. The
@@ -176,7 +176,7 @@ extension Unsafe${Mutable}BufferPointer: ${Mutable}Collection, RandomAccessColle
176176
i -= 1
177177
}
178178

179-
@inlinable
179+
@inlinable // unsafe-performance
180180
public func index(_ i: Int, offsetBy n: Int) -> Int {
181181
// NOTE: this is a manual specialization of index movement for a Strideable
182182
// index that is required for UnsafeBufferPointer performance. The
@@ -186,7 +186,7 @@ extension Unsafe${Mutable}BufferPointer: ${Mutable}Collection, RandomAccessColle
186186
return i + n
187187
}
188188

189-
@inlinable
189+
@inlinable // unsafe-performance
190190
public func index(_ i: Int, offsetBy n: Int, limitedBy limit: Int) -> Int? {
191191
// NOTE: this is a manual specialization of index movement for a Strideable
192192
// index that is required for UnsafeBufferPointer performance. The
@@ -200,7 +200,7 @@ extension Unsafe${Mutable}BufferPointer: ${Mutable}Collection, RandomAccessColle
200200
return i + n
201201
}
202202

203-
@inlinable
203+
@inlinable // unsafe-performance
204204
public func distance(from start: Int, to end: Int) -> Int {
205205
// NOTE: this is a manual specialization of index movement for a Strideable
206206
// index that is required for UnsafeBufferPointer performance. The
@@ -210,21 +210,21 @@ extension Unsafe${Mutable}BufferPointer: ${Mutable}Collection, RandomAccessColle
210210
return end - start
211211
}
212212

213-
@inlinable
213+
@inlinable // unsafe-performance
214214
public func _failEarlyRangeCheck(_ index: Int, bounds: Range<Int>) {
215215
// NOTE: In release mode, this method is a no-op for performance reasons.
216216
_debugPrecondition(index >= bounds.lowerBound)
217217
_debugPrecondition(index < bounds.upperBound)
218218
}
219219

220-
@inlinable
220+
@inlinable // unsafe-performance
221221
public func _failEarlyRangeCheck(_ range: Range<Int>, bounds: Range<Int>) {
222222
// NOTE: In release mode, this method is a no-op for performance reasons.
223223
_debugPrecondition(range.lowerBound >= bounds.lowerBound)
224224
_debugPrecondition(range.upperBound <= bounds.upperBound)
225225
}
226226

227-
@inlinable
227+
@inlinable // unsafe-performance
228228
public var indices: Indices {
229229
return startIndex..<endIndex
230230
}
@@ -265,7 +265,7 @@ extension Unsafe${Mutable}BufferPointer: ${Mutable}Collection, RandomAccessColle
265265
///
266266
/// - Parameter i: The position of the element to access. `i` must be in the
267267
/// range `0..<count`.
268-
@inlinable
268+
@inlinable // unsafe-performance
269269
public subscript(i: Int) -> Element {
270270
get {
271271
_debugPrecondition(i >= 0)
@@ -318,7 +318,7 @@ extension Unsafe${Mutable}BufferPointer: ${Mutable}Collection, RandomAccessColle
318318
///
319319
/// - Parameter bounds: A range of the buffer's indices. The bounds of
320320
/// the range must be valid indices of the buffer.
321-
@inlinable
321+
@inlinable // unsafe-performance
322322
public subscript(bounds: Range<Int>)
323323
-> Slice<Unsafe${Mutable}BufferPointer<Element>>
324324
{
@@ -354,7 +354,7 @@ extension Unsafe${Mutable}BufferPointer: ${Mutable}Collection, RandomAccessColle
354354
/// - Parameters:
355355
/// - i: The index of the first value to swap.
356356
/// - j: The index of the second value to swap.
357-
@inlinable
357+
@inlinable // unsafe-performance
358358
public func swapAt(_ i: Int, _ j: Int) {
359359
guard i != j else { return }
360360
_debugPrecondition(i >= 0 && j >= 0)
@@ -379,7 +379,7 @@ extension Unsafe${Mutable}BufferPointer {
379379
/// `MemoryLayout<Element>.alignment`.
380380
/// - count: The number of instances in the buffer. `count` must not be
381381
/// negative.
382-
@inlinable
382+
@inlinable // unsafe-performance
383383
public init(start: Unsafe${Mutable}Pointer<Element>?, count: Int) {
384384
_precondition(
385385
count >= 0, "Unsafe${Mutable}BufferPointer with negative count")
@@ -390,7 +390,7 @@ extension Unsafe${Mutable}BufferPointer {
390390
self.count = count
391391
}
392392

393-
@inlinable
393+
@inlinable // unsafe-performance
394394
public init(_empty: ()) {
395395
_position = nil
396396
count = 0
@@ -402,7 +402,7 @@ extension Unsafe${Mutable}BufferPointer {
402402
/// given immutable buffer pointer.
403403
///
404404
/// - Parameter other: The immutable buffer pointer to convert.
405-
@inlinable
405+
@inlinable // unsafe-performance
406406
public init(mutating other: UnsafeBufferPointer<Element>) {
407407
_position = UnsafeMutablePointer<Element>(mutating: other._position)
408408
count = other.count
@@ -414,7 +414,7 @@ extension Unsafe${Mutable}BufferPointer {
414414
/// given mutable buffer pointer.
415415
///
416416
/// - Parameter other: The mutable buffer pointer to convert.
417-
@inlinable
417+
@inlinable // unsafe-performance
418418
public init(_ other: UnsafeMutableBufferPointer<Element>) {
419419
_position = UnsafePointer<Element>(other._position)
420420
count = other.count
@@ -443,7 +443,7 @@ extension Unsafe${Mutable}BufferPointer {
443443
/// - `rebased.count == slice.count`
444444
///
445445
/// - Parameter slice: The buffer slice to rebase.
446-
@inlinable
446+
@inlinable // unsafe-performance
447447
public init(rebasing slice: Slice<UnsafeBufferPointer<Element>>) {
448448
self.init(start: slice.base.baseAddress! + slice.startIndex,
449449
count: slice.count)
@@ -470,7 +470,7 @@ extension Unsafe${Mutable}BufferPointer {
470470
/// - `rebased.count == slice.count`
471471
///
472472
/// - Parameter slice: The buffer slice to rebase.
473-
@inlinable
473+
@inlinable // unsafe-performance
474474
public init(rebasing slice: Slice<UnsafeMutableBufferPointer<Element>>) {
475475
self.init(
476476
start: slice.base.baseAddress! + slice.startIndex,
@@ -485,7 +485,7 @@ extension Unsafe${Mutable}BufferPointer {
485485
/// `nil`, this function does nothing. Otherwise, the memory must not be initialized
486486
/// or `Pointee` must be a trivial type. This buffer pointer's `count` must
487487
/// be equal to the originally allocated size of the memory block.
488-
@inlinable
488+
@inlinable // unsafe-performance
489489
public func deallocate() {
490490
_position?.deallocate()
491491
}
@@ -513,7 +513,7 @@ extension Unsafe${Mutable}BufferPointer {
513513
///
514514
/// - Parameter count: The amount of memory to allocate, counted in instances
515515
/// of `Element`.
516-
@inlinable
516+
@inlinable // unsafe-performance
517517
public static func allocate(capacity count: Int)
518518
-> UnsafeMutableBufferPointer<Element> {
519519
let size = MemoryLayout<Element>.stride * count
@@ -531,7 +531,7 @@ extension Unsafe${Mutable}BufferPointer {
531531
///
532532
/// - Parameters:
533533
/// - repeatedValue: The instance to initialize this buffer's memory with.
534-
@inlinable
534+
@inlinable // unsafe-performance
535535
public func initialize(repeating repeatedValue: Element) {
536536
guard let dstBase = _position else {
537537
return
@@ -551,7 +551,7 @@ extension Unsafe${Mutable}BufferPointer {
551551
/// Warning: All buffer elements must be initialized before calling this.
552552
/// Assigning to part of the buffer must be done using the `assign(repeating:count:)``
553553
/// method on the buffer’s `baseAddress`.
554-
@inlinable
554+
@inlinable // unsafe-performance
555555
public func assign(repeating repeatedValue: Element) {
556556
guard let dstBase = _position else {
557557
return
@@ -600,7 +600,7 @@ extension Unsafe${Mutable}BufferPointer {
600600
/// value is also used as the return value for the `withMemoryRebound(to:_:)`
601601
/// method.
602602
/// - Returns: The return value, if any, of the `body` closure parameter.
603-
@inlinable
603+
@inlinable // unsafe-performance
604604
public func withMemoryRebound<T, Result>(
605605
to type: T.Type, _ body: (${Self}<T>) throws -> Result
606606
) rethrows -> Result {
@@ -623,7 +623,7 @@ extension Unsafe${Mutable}BufferPointer {
623623
///
624624
/// If the `baseAddress` of this buffer is `nil`, the count is zero. However,
625625
/// a buffer can have a `count` of zero even with a non-`nil` base address.
626-
@inlinable
626+
@inlinable // unsafe-performance
627627
public var baseAddress: Unsafe${Mutable}Pointer<Element>? {
628628
return _position
629629
}
@@ -660,7 +660,7 @@ extension UnsafeMutableBufferPointer {
660660
/// - Returns: An iterator to any elements of `source` that didn't fit in the
661661
/// buffer, and an index to the point in the buffer one past the last
662662
/// element written.
663-
@inlinable
663+
@inlinable // unsafe-performance
664664
public func initialize<S: Sequence>(from source: S) -> (S.Iterator, Index)
665665
where S.Element == Element {
666666
return source._copyContents(initializing: self)

0 commit comments

Comments
 (0)