DVUI

setSliceCopies

Parameters

#
self:*Data
*Data
gpa:std.mem.Allocator
std.mem.Allocator
key:Key
Key
data:anytype
anytype
num_copies:usize
usize

Source

Implementation

#
pub fn setSliceCopies(self: *Data, gpa: std.mem.Allocator, key: Key, data: anytype, num_copies: usize) std.mem.Allocator.Error!void {
    const S = @TypeOf(data);
    const sentinel = @typeInfo(Slice(S)).pointer.sentinel();
    const slice, _ = try self.getOrPutSliceT(gpa, key, Slice(S), data.len * num_copies, true);

    // if slice and data alias it means dataSetSlice was called with the slice
    // from dataGetSlice, so it already has the data
    if (slice.ptr != data.ptr) {
        for (0..num_copies) |i| {
            @memcpy(slice[i * data.len ..][0..data.len], data);
        }
    }
    if (sentinel) |s| slice[slice.len - 1] = s;
}