list single in zig

This commit is contained in:
Folkert 2021-05-01 16:38:11 +02:00
parent 7b885f2e7c
commit 586727f74a
5 changed files with 44 additions and 21 deletions

View file

@ -626,6 +626,18 @@ pub fn listRepeat(count: usize, alignment: usize, element: Opaque, element_width
}
}
pub fn listSingle(alignment: usize, element: Opaque, element_width: usize) callconv(.C) RocList {
var output = RocList.allocate(std.heap.c_allocator, alignment, 1, element_width);
if (output.bytes) |target| {
if (element) |source| {
@memcpy(target, source, element_width);
}
}
return output;
}
pub fn listAppend(list: RocList, alignment: usize, element: Opaque, element_width: usize) callconv(.C) RocList {
const old_length = list.len();
var output = list.reallocate(std.heap.c_allocator, alignment, old_length + 1, element_width);