mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 12:18:19 +00:00
add refcount constants
This commit is contained in:
parent
ad41b509cf
commit
a7e4a55e1e
3 changed files with 11 additions and 6 deletions
|
@ -582,6 +582,9 @@ impl Hash for U128 {
|
|||
}
|
||||
}
|
||||
|
||||
pub const ROC_REFCOUNT_CONSTANT: usize = 0;
|
||||
pub const ROC_REFCOUNT_ONE: usize = isize::MIN as usize;
|
||||
|
||||
/// All Roc types that are refcounted must implement this trait.
|
||||
///
|
||||
/// For aggregate types, this must recurse down the structure.
|
||||
|
|
|
@ -14,7 +14,9 @@ use core::{
|
|||
};
|
||||
use std::{cmp::max, ops::Range};
|
||||
|
||||
use crate::{roc_alloc, roc_dealloc, roc_realloc, storage::Storage, RocRefcounted};
|
||||
use crate::{
|
||||
roc_alloc, roc_dealloc, roc_realloc, storage::Storage, RocRefcounted, ROC_REFCOUNT_CONSTANT,
|
||||
};
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
use core::marker::PhantomData;
|
||||
|
@ -680,7 +682,7 @@ where
|
|||
unsafe {
|
||||
let value = std::ptr::read(ptr);
|
||||
// Only safe to write to the pointer if it is not constant (0)
|
||||
if value != 0 {
|
||||
if value != ROC_REFCOUNT_CONSTANT {
|
||||
std::ptr::write(ptr, (value as isize + 1) as usize);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ use core::{
|
|||
use std::ffi::{CStr, CString};
|
||||
use std::{ops::Range, ptr::NonNull};
|
||||
|
||||
use crate::{roc_realloc, RocList, RocRefcounted};
|
||||
use crate::{roc_realloc, RocList, RocRefcounted, ROC_REFCOUNT_CONSTANT};
|
||||
|
||||
#[repr(transparent)]
|
||||
pub struct RocStr(RocStrInner);
|
||||
|
@ -944,8 +944,8 @@ impl BigString {
|
|||
|
||||
let ptr = self.ptr_to_refcount();
|
||||
// Only safe to write to the pointer if it is not constant (0)
|
||||
if unsafe { std::ptr::read(ptr) } != 0 {
|
||||
unsafe { std::ptr::write(ptr, 0) }
|
||||
if unsafe { std::ptr::read(ptr) } != ROC_REFCOUNT_CONSTANT {
|
||||
unsafe { std::ptr::write(ptr, ROC_REFCOUNT_CONSTANT) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -954,7 +954,7 @@ impl BigString {
|
|||
unsafe {
|
||||
let value = std::ptr::read(ptr);
|
||||
// Only safe to write to the pointer if it is not constant (0)
|
||||
if value != 0 {
|
||||
if value != ROC_REFCOUNT_CONSTANT {
|
||||
std::ptr::write(ptr, (value as isize + 1) as usize);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue