mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-02 11:22:19 +00:00
Improve some RocList functions in zig
This commit is contained in:
parent
6f5baa5021
commit
ce6c2f330c
1 changed files with 11 additions and 8 deletions
|
@ -31,11 +31,16 @@ pub const RocList = extern struct {
|
|||
return RocList{ .bytes = null, .length = 0, .capacity = 0 };
|
||||
}
|
||||
|
||||
pub fn isEq(self: RocList, other: RocList) bool {
|
||||
if ((self.len() != other.len()) or self.isEmpty()) {
|
||||
pub fn eql(self: RocList, other: RocList) bool {
|
||||
if (self.len() != other.len()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Their lengths are the same, and one is empty; they're both empty!
|
||||
if (self.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var index: usize = 0;
|
||||
const self_bytes = self.bytes orelse unreachable;
|
||||
const other_bytes = other.bytes orelse unreachable;
|
||||
|
@ -69,12 +74,10 @@ pub const RocList = extern struct {
|
|||
utils.decref(self.bytes, self.len(), @alignOf(T));
|
||||
}
|
||||
|
||||
pub fn elements(self: RocList, comptime T: type) [*]T {
|
||||
const refcount_byte_count = math.max(@alignOf(usize), @alignOf(T));
|
||||
const addr = @ptrToInt(self.bytes) + refcount_byte_count;
|
||||
|
||||
// The first element is stored right after the refcount.
|
||||
return @intToPtr([*]T, addr);
|
||||
pub fn elements(self: RocList, comptime T: type) ?[*]T {
|
||||
// Is there a better way to make this cast happen?
|
||||
// @ptrCast gives an error because this increases alignment.
|
||||
return @intToPtr(?[*]T, @ptrToInt(self.bytes));
|
||||
}
|
||||
|
||||
pub fn isUnique(self: RocList) bool {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue