Skip to content

Commit 134fc4d

Browse files
committed
[stdlib] BitwiseCopyable storeBytes overload.
The new overload is constrained to BitwiseCopyable and so enjoys the use of BitwiseCopyableArchetypeTypeInfo.
1 parent bca1dd7 commit 134fc4d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

stdlib/public/core/UnsafeRawPointer.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,20 @@ public struct UnsafeMutableRawPointer: _Pointer {
13101310
/// - offset: The offset from this pointer, in bytes. `offset` must be
13111311
/// nonnegative. The default is zero.
13121312
/// - type: The type of `value`.
1313+
#if $BitwiseCopyable
1314+
@inlinable
1315+
@_alwaysEmitIntoClient
1316+
public func storeBytes<T : _BitwiseCopyable>(
1317+
of value: T, toByteOffset offset: Int = 0, as type: T.Type
1318+
) {
1319+
withUnsafePointer(to: value) { source in
1320+
_memcpy(
1321+
dest: (self + offset),
1322+
src: source,
1323+
size: UInt(MemoryLayout<T>.size))
1324+
}
1325+
}
1326+
#endif
13131327
@inlinable
13141328
@_alwaysEmitIntoClient
13151329
// This custom silgen name is chosen to not interfere with the old ABI

0 commit comments

Comments
 (0)