mirror of
https://github.com/roc-lang/roc.git
synced 2024-11-11 05:34:11 +03:00
Add RocList.first_elem_ptr to list.zig
This commit is contained in:
parent
f82d515894
commit
ff596f5e75
@ -3,6 +3,7 @@ const utils = @import("utils.zig");
|
||||
const RocResult = utils.RocResult;
|
||||
const UpdateMode = utils.UpdateMode;
|
||||
const mem = std.mem;
|
||||
const math = std.math;
|
||||
|
||||
const EqFn = fn (?[*]u8, ?[*]u8) callconv(.C) bool;
|
||||
const CompareFn = fn (?[*]u8, ?[*]u8, ?[*]u8) callconv(.C) u8;
|
||||
@ -30,6 +31,14 @@ pub const RocList = extern struct {
|
||||
return RocList{ .bytes = null, .length = 0, .capacity = 0 };
|
||||
}
|
||||
|
||||
pub fn first_elem_ptr(self: RocList, comptime elem_type: type) [*]elem_type {
|
||||
const refcount_byte_count = math.max(@alignOf(usize), @alignOf(elem_type));
|
||||
const addr = @ptrToInt(self.bytes) + refcount_byte_count;
|
||||
|
||||
// The first element is stored right after the refcount.
|
||||
return @intToPtr([*]elem_type, addr);
|
||||
}
|
||||
|
||||
pub fn isUnique(self: RocList) bool {
|
||||
// the empty list is unique (in the sense that copying it will not leak memory)
|
||||
if (self.isEmpty()) {
|
||||
|
Loading…
Reference in New Issue
Block a user