Skip to content

Commit c66a445

Browse files
authored
[stdlib] Make some more *Pointer operations _transparent (#21126)
Not only was this affecting performance when building from parseable interfaces, but we'd also want these to be inlined for any sort of bounds-checking diagnostics / static analysis we might get in the future.
1 parent 047c55c commit c66a445

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

stdlib/public/core/Pointer.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ extension _Pointer /*: Strideable*/ {
165165
///
166166
/// - Returns: A pointer advanced from this pointer by
167167
/// `MemoryLayout<Pointee>.stride` bytes.
168-
@inlinable
168+
@_transparent
169169
public func successor() -> Self {
170170
return advanced(by: 1)
171171
}
@@ -177,7 +177,7 @@ extension _Pointer /*: Strideable*/ {
177177
///
178178
/// - Returns: A pointer shifted backward from this pointer by
179179
/// `MemoryLayout<Pointee>.stride` bytes.
180-
@inlinable
180+
@_transparent
181181
public func predecessor() -> Self {
182182
return advanced(by: -1)
183183
}
@@ -199,7 +199,7 @@ extension _Pointer /*: Strideable*/ {
199199
/// - Returns: The distance from this pointer to `end`, in strides of the
200200
/// pointer's `Pointee` type. To access the stride, use
201201
/// `MemoryLayout<Pointee>.stride`.
202-
@inlinable
202+
@_transparent
203203
public func distance(to end: Self) -> Int {
204204
return
205205
Int(Builtin.sub_Word(Builtin.ptrtoint_Word(end._rawValue),
@@ -222,7 +222,7 @@ extension _Pointer /*: Strideable*/ {
222222
/// zero.
223223
/// - Returns: A pointer offset from this pointer by `n` instances of the
224224
/// `Pointee` type.
225-
@inlinable
225+
@_transparent
226226
public func advanced(by n: Int) -> Self {
227227
return Self(Builtin.gep_Word(
228228
self._rawValue, n._builtinWordValue, Pointee.self))
@@ -264,7 +264,7 @@ extension Int {
264264
///
265265
/// - Parameter pointer: The pointer to use as the source for the new
266266
/// integer.
267-
@inlinable
267+
@_transparent
268268
public init<P: _Pointer>(bitPattern pointer: P?) {
269269
if let pointer = pointer {
270270
self = Int(Builtin.ptrtoint_Word(pointer._rawValue))
@@ -282,7 +282,7 @@ extension UInt {
282282
///
283283
/// - Parameter pointer: The pointer to use as the source for the new
284284
/// integer.
285-
@inlinable
285+
@_transparent
286286
public init<P: _Pointer>(bitPattern pointer: P?) {
287287
if let pointer = pointer {
288288
self = UInt(Builtin.ptrtoint_Word(pointer._rawValue))

stdlib/public/core/UnsafeRawPointer.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ public struct UnsafeRawPointer: _Pointer {
332332

333333
extension UnsafeRawPointer: Strideable {
334334
// custom version for raw pointers
335-
@inlinable
335+
@_transparent
336336
public func advanced(by n: Int) -> UnsafeRawPointer {
337337
return UnsafeRawPointer(Builtin.gepRaw_Word(_rawValue, n._builtinWordValue))
338338
}
@@ -937,30 +937,30 @@ public struct UnsafeMutableRawPointer: _Pointer {
937937

938938
extension UnsafeMutableRawPointer: Strideable {
939939
// custom version for raw pointers
940-
@inlinable
940+
@_transparent
941941
public func advanced(by n: Int) -> UnsafeMutableRawPointer {
942942
return UnsafeMutableRawPointer(Builtin.gepRaw_Word(_rawValue, n._builtinWordValue))
943943
}
944944
}
945945

946946
extension OpaquePointer {
947-
@inlinable
947+
@_transparent
948948
public init(_ from: UnsafeMutableRawPointer) {
949949
self._rawValue = from._rawValue
950950
}
951951

952-
@inlinable
952+
@_transparent
953953
public init?(_ from: UnsafeMutableRawPointer?) {
954954
guard let unwrapped = from else { return nil }
955955
self._rawValue = unwrapped._rawValue
956956
}
957957

958-
@inlinable
958+
@_transparent
959959
public init(_ from: UnsafeRawPointer) {
960960
self._rawValue = from._rawValue
961961
}
962962

963-
@inlinable
963+
@_transparent
964964
public init?(_ from: UnsafeRawPointer?) {
965965
guard let unwrapped = from else { return nil }
966966
self._rawValue = unwrapped._rawValue

0 commit comments

Comments
 (0)