mirror of
https://github.com/loro-dev/loro.git
synced 2025-01-22 21:07:43 +00:00
refactor: make Bump mode newtype
This commit is contained in:
parent
c7d3e01087
commit
a3df07bf5c
1 changed files with 11 additions and 4 deletions
|
@ -4,7 +4,14 @@ use std::{
|
|||
ops::{Deref, DerefMut, Index, RangeBounds, IndexMut},
|
||||
};
|
||||
|
||||
pub use bumpalo::Bump;
|
||||
|
||||
/// [Bump] will use [bumpalo] to allocate nodes, where allocation is fast but no deallocation happens before [crate::RleTree] dropped.
|
||||
///
|
||||
/// NOTE: Should be cautious when using [Bump] mode, T's drop method won't be called in this mode.
|
||||
/// So you cannot use smart pointer in [Bump] mode directly. You should wrap it inside [bumpalo]'s [bumpalo::boxed::Box];
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Bump(bumpalo::Bump);
|
||||
|
||||
fn test() {
|
||||
let _a = vec![1, 2];
|
||||
}
|
||||
|
@ -88,7 +95,7 @@ impl<'bump, T: Debug + 'bump> VecTrait<'bump, T> for BumpVec<'bump, T> {
|
|||
|
||||
#[inline(always)]
|
||||
fn with_capacity_in(capacity: usize, arena: &'bump Self::Arena) -> BumpVec<'bump, T> {
|
||||
BumpVec::with_capacity_in(capacity, arena)
|
||||
BumpVec::with_capacity_in(capacity, &arena.0)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
@ -161,11 +168,11 @@ impl Arena for Bump {
|
|||
where
|
||||
T: 'a + Debug,
|
||||
{
|
||||
self.alloc(value)
|
||||
self.0.alloc(value)
|
||||
}
|
||||
|
||||
fn allocated_bytes(&self) -> usize {
|
||||
Bump::allocated_bytes(self)
|
||||
bumpalo::Bump::allocated_bytes(&self.0)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue