Skip to content

Commit c5b3316

Browse files
committed
[stdlib] the core of memory rebinding, unchecked
1 parent aca36f5 commit c5b3316

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

stdlib/public/core/UnsafePointer.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,19 @@ extension UnsafePointer where Pointee: ~Copyable {
410410
),
411411
"self must be a properly aligned pointer for types Pointee and T"
412412
)
413+
return try unsafe _uncheckedWithMemoryRebound(
414+
to: type, capacity: count, body)
415+
}
416+
417+
@_alwaysEmitIntoClient
418+
@_transparent
419+
internal func _uncheckedWithMemoryRebound<
420+
T: ~Copyable, E: Error, Result: ~Copyable
421+
>(
422+
to type: T.Type,
423+
capacity count: Int,
424+
_ body: (_ pointer: UnsafePointer<T>) throws(E) -> Result
425+
) throws(E) -> Result {
413426
let binding = Builtin.bindMemory(_rawValue, count._builtinWordValue, T.self)
414427
defer { Builtin.rebindMemory(_rawValue, binding) }
415428
return try unsafe body(.init(_rawValue))

0 commit comments

Comments
 (0)