Skip to content

Commit bf866ef

Browse files
committed
Avoid casting through UInt on 64-bit where we can just rebind the whole buffer to Address
1 parent 924a6e5 commit bf866ef

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
@@ -85,9 +85,17 @@ public struct Backtrace: Sendable {
8585
#endif
8686

8787
let endIndex = addresses.index(addresses.startIndex, offsetBy: initializedCount)
88-
return addresses[..<endIndex].withMemoryRebound(to: UnsafeRawPointer?.self) { addresses in
88+
#if _pointerBitWidth(_64)
89+
// The width of a pointer equals the width of an `Address`, so we can just
90+
// bitcast the memory rather than mapping through UInt first.
91+
return addresses[..<endIndex].withMemoryRebound(to: Address.self) { addresses in
8992
Self(addresses: addresses)
9093
}
94+
#else
95+
return addresses[..<endIndex].withMemoryRebound(to: UnsafeRawPointer?.self) { addresses in
96+
return Self(addresses: addresses)
97+
}
98+
#endif
9199
}
92100
}
93101
}

0 commit comments

Comments
 (0)