mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 16:44:33 +00:00
list single in zig
This commit is contained in:
parent
7b885f2e7c
commit
586727f74a
5 changed files with 44 additions and 21 deletions
|
@ -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);
|
||||
|
|
|
@ -19,6 +19,7 @@ comptime {
|
|||
exportListFn(list.listContains, "contains");
|
||||
exportListFn(list.listRepeat, "repeat");
|
||||
exportListFn(list.listAppend, "append");
|
||||
exportListFn(list.listSingle, "single");
|
||||
exportListFn(list.listJoin, "join");
|
||||
exportListFn(list.listRange, "range");
|
||||
exportListFn(list.listReverse, "reverse");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue