mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-02 11:22:19 +00:00
cleanup constant refcount checking
This commit is contained in:
parent
e96affe992
commit
c6d594a758
1 changed files with 16 additions and 2 deletions
|
@ -210,7 +210,7 @@ pub fn increfRcPtrC(ptr_to_refcount: *isize, amount: isize) callconv(.C) void {
|
|||
|
||||
// Ensure that the refcount is not whole program lifetime.
|
||||
const refcount: isize = ptr_to_refcount.*;
|
||||
if (refcount != REFCOUNT_MAX_ISIZE) {
|
||||
if (!rcConstant(refcount)) {
|
||||
// Note: we assume that a refcount will never overflow.
|
||||
// As such, we do not need to cap incrementing.
|
||||
switch (RC_TYPE) {
|
||||
|
@ -373,7 +373,7 @@ inline fn decref_ptr_to_refcount(
|
|||
|
||||
// Ensure that the refcount is not whole program lifetime.
|
||||
const refcount: isize = refcount_ptr[0];
|
||||
if (refcount != REFCOUNT_MAX_ISIZE) {
|
||||
if (!rcConstant(refcount)) {
|
||||
switch (RC_TYPE) {
|
||||
.normal => {
|
||||
const old = @as(usize, @bitCast(refcount));
|
||||
|
@ -441,6 +441,20 @@ pub fn rcUnique(refcount: isize) bool {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn rcConstant(refcount: isize) bool {
|
||||
switch (RC_TYPE) {
|
||||
.normal => {
|
||||
return refcount == REFCOUNT_MAX_ISIZE;
|
||||
},
|
||||
.atomic => {
|
||||
return refcount & REFCOUNT_VALUE_MASK == REFCOUNT_MAX_ISIZE & REFCOUNT_VALUE_MASK;
|
||||
},
|
||||
.none => {
|
||||
return true;
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// We follow roughly the [fbvector](https://github.com/facebook/folly/blob/main/folly/docs/FBVector.md) when it comes to growing a RocList.
|
||||
// Here is [their growth strategy](https://github.com/facebook/folly/blob/3e0525988fd444201b19b76b390a5927c15cb697/folly/FBVector.h#L1128) for push_back:
|
||||
//
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue