Skip to content

Commit 3e739f6

Browse files
authored
Merge pull request #42076 from glessard/se-withMemoryRebound
[stdlib] remove preconditions from compatibility entry point
2 parents 30034d3 + ce7d813 commit 3e739f6

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

stdlib/public/core/UnsafePointer.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,9 @@ public struct UnsafePointer<Pointee>: _Pointer {
336336
capacity count: Int,
337337
_ body: (UnsafePointer<T>) throws -> Result
338338
) rethrows -> Result {
339-
return try withMemoryRebound(to: T.self, capacity: count, body)
339+
let binding = Builtin.bindMemory(_rawValue, count._builtinWordValue, T.self)
340+
defer { Builtin.rebindMemory(_rawValue, binding) }
341+
return try body(.init(_rawValue))
340342
}
341343

342344
/// Accesses the pointee at the specified offset from this pointer.
@@ -1040,7 +1042,9 @@ public struct UnsafeMutablePointer<Pointee>: _Pointer {
10401042
capacity count: Int,
10411043
_ body: (UnsafeMutablePointer<T>) throws -> Result
10421044
) rethrows -> Result {
1043-
return try withMemoryRebound(to: T.self, capacity: count, body)
1045+
let binding = Builtin.bindMemory(_rawValue, count._builtinWordValue, T.self)
1046+
defer { Builtin.rebindMemory(_rawValue, binding) }
1047+
return try body(.init(_rawValue))
10441048
}
10451049

10461050
/// Accesses the pointee at the specified offset from this pointer.

0 commit comments

Comments
 (0)