cl-arena: Make arena constructors const fn

This commit is contained in:
John 2024-04-27 16:52:20 -05:00
parent ecf97801d6
commit 83423f37be

View File

@ -96,18 +96,18 @@ pub mod typed_arena {
impl<T> Default for TypedArena<T> { impl<T> Default for TypedArena<T> {
fn default() -> Self { fn default() -> Self {
Self { Self::new()
_drops: Default::default(),
chunks: Default::default(),
head: Cell::new(ptr::null_mut()),
tail: Cell::new(ptr::null_mut()),
}
} }
} }
impl<T> TypedArena<T> { impl<T> TypedArena<T> {
pub fn new() -> Self { pub const fn new() -> Self {
Self::default() Self {
_drops: PhantomData,
chunks: RefCell::new(Vec::new()),
head: Cell::new(ptr::null_mut()),
tail: Cell::new(ptr::null_mut()),
}
} }
#[allow(clippy::mut_from_ref)] #[allow(clippy::mut_from_ref)]
@ -205,17 +205,17 @@ pub mod dropless_arena {
impl Default for DroplessArena { impl Default for DroplessArena {
fn default() -> Self { fn default() -> Self {
Self { Self::new()
chunks: Default::default(),
head: Cell::new(ptr::null_mut()),
tail: Cell::new(ptr::null_mut()),
}
} }
} }
impl DroplessArena { impl DroplessArena {
pub fn new() -> Self { pub const fn new() -> Self {
Self::default() Self {
chunks: RefCell::new(Vec::new()),
head: Cell::new(ptr::null_mut()),
tail: Cell::new(ptr::null_mut()),
}
} }
/// Allocates a `T` in the [DroplessArena], and returns a mutable reference to it. /// Allocates a `T` in the [DroplessArena], and returns a mutable reference to it.