Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

copyForwards

memmove.copyForwards
inline fn copyForwards(
    dest: [*]u8,
    src: [*]const u8,
    len: usize,
) void

File

lib/compiler_rt/memmove.zig:145

Code

inline fn copyForwards(
    dest: [*]u8,
    src: [*]const u8,
    len: usize,
) void {
    @setRuntimeSafety(compiler_rt.test_safety);
    assert(len >= 2 * @sizeOf(Element));

    const head = src[0..@sizeOf(Element)].*;
    const tail = src[len - @sizeOf(Element) ..][0..@sizeOf(Element)].*;
    const alignment_offset = @alignOf(Element) - @intFromPtr(src) % @alignOf(Element);
    const n = len - alignment_offset;
    const d = dest + alignment_offset;
    const s = src + alignment_offset;

    copyBlocksAlignedSource(@ptrCast(d), @ptrCast(@alignCast(s)), n);

    // copy last `copy_size` bytes unconditionally, since block copy
    // methods only copy a multiple of `copy_size` bytes.
    dest[len - @sizeOf(Element) ..][0..@sizeOf(Element)].* = tail;
    dest[0..@sizeOf(Element)].* = head;
}