Function writeSplat [src]

If the number of bytes to write based on data and splat fits inside unusedCapacitySlice, this function is guaranteed to not fail, not call into VTable, and return the full number of bytes.

Prototype

pub fn writeSplat(w: *Writer, data: []const []const u8, splat: usize) Error!usize

Parameters

w: *Writerdata: []const []const u8splat: usize

Possible Errors

WriteFailed

See the Writer implementation for detailed diagnostics.

Source

pub fn writeSplat(w: *Writer, data: []const []const u8, splat: usize) Error!usize { assert(data.len > 0); const buffer = w.buffer; const count = countSplat(data, splat); if (w.end + count > buffer.len) return w.vtable.drain(w, data, splat); for (data[0 .. data.len - 1]) |bytes| { @memcpy(buffer[w.end..][0..bytes.len], bytes); w.end += bytes.len; } const pattern = data[data.len - 1]; switch (pattern.len) { 0 => {}, 1 => { @memset(buffer[w.end..][0..splat], pattern[0]); w.end += splat; }, else => for (0..splat) |_| { @memcpy(buffer[w.end..][0..pattern.len], pattern); w.end += pattern.len; }, } return count; }