Skip to content

Commit 0041b5d

Browse files
committed
Avoid casting through UInt on 64-bit where we can just rebind the whole buffer to Address
1 parent 011f7fd commit 0041b5d

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Sources/Testing/SourceAttribution/Backtrace.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,17 @@ public struct Backtrace: Sendable {
8181
#endif
8282

8383
let endIndex = addresses.index(addresses.startIndex, offsetBy: initializedCount)
84-
return addresses[..<endIndex].withMemoryRebound(to: UnsafeRawPointer?.self) { addresses in
84+
#if _pointerBitWidth(_64)
85+
// The width of a pointer equals the width of an `Address`, so we can just
86+
// bitcast the memory rather than mapping through UInt first.
87+
return addresses[..<endIndex].withMemoryRebound(to: Address.self) { addresses in
8588
Self(addresses: addresses)
8689
}
90+
#else
91+
return addresses[..<endIndex].withMemoryRebound(to: UnsafeRawPointer?.self) { addresses in
92+
return Self(addresses: addresses)
93+
}
94+
#endif
8795
}
8896
}
8997
}

0 commit comments

Comments
 (0)