mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 16:21:11 +00:00
Simplify Refcounting
Instead of -max_size to -1 for regular refcounts, use 1 to max_size. 0 still means constant refcount. The highest bit is used to signify atomic refcounting required. This does not turn on any sort of atomic refcounting.
This commit is contained in:
parent
8001de5468
commit
4b8693537a
15 changed files with 57 additions and 84 deletions
|
@ -179,23 +179,19 @@ pub const RocList = extern struct {
|
|||
}
|
||||
|
||||
pub fn isUnique(self: RocList) bool {
|
||||
return self.refcountMachine() == utils.REFCOUNT_ONE;
|
||||
return utils.rcUnique(@bitCast(self.refcount()));
|
||||
}
|
||||
|
||||
fn refcountMachine(self: RocList) usize {
|
||||
fn refcount(self: RocList) usize {
|
||||
if (self.getCapacity() == 0 and !self.isSeamlessSlice()) {
|
||||
// the zero-capacity is Clone, copying it will not leak memory
|
||||
return utils.REFCOUNT_ONE;
|
||||
return 1;
|
||||
}
|
||||
|
||||
const ptr: [*]usize = @as([*]usize, @ptrCast(@alignCast(self.getAllocationDataPtr())));
|
||||
return (ptr - 1)[0];
|
||||
}
|
||||
|
||||
fn refcountHuman(self: RocList) usize {
|
||||
return self.refcountMachine() - utils.REFCOUNT_ONE + 1;
|
||||
}
|
||||
|
||||
pub fn makeUniqueExtra(self: RocList, alignment: u32, element_width: usize, elements_refcounted: bool, dec: Dec, update_mode: UpdateMode) RocList {
|
||||
if (update_mode == .InPlace) {
|
||||
return self;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue