remove bump in generational box
This commit is contained in:
1 parent
88e2da6c11
commit
65c0d213e3
2 files changed
+2
-7
No files matched your search
@@ -10,7 +10,6 @@ keywords = ["generational", "box", "memory", "allocator"]
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bumpalo = { version = "3.6" }
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
|
|||||||
@@ -11,8 +11,6 @@ use std::{
|
|||||||
rc::Rc,
|
rc::Rc,
|
||||||
};
|
};
|
||||||
|
|
||||||
use bumpalo::Bump;
|
|
||||||
|
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```compile_fail
|
/// ```compile_fail
|
||||||
@@ -615,14 +613,12 @@ impl Drop for GenerationalRefMutBorrowInfo {
|
|||||||
/// Handles recycling generational boxes that have been dropped. Your application should have one store or one store per thread.
|
/// Handles recycling generational boxes that have been dropped. Your application should have one store or one store per thread.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Store {
|
pub struct Store {
|
||||||
bump: &'static Bump,
|
|
||||||
recycled: Rc<RefCell<Vec<MemoryLocation>>>,
|
recycled: Rc<RefCell<Vec<MemoryLocation>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Store {
|
impl Default for Store {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
bump: Box::leak(Box::new(Bump::new())),
|
|
||||||
recycled: Default::default(),
|
recycled: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -638,7 +634,7 @@ impl Store {
|
|||||||
if let Some(location) = self.recycled.borrow_mut().pop() {
|
if let Some(location) = self.recycled.borrow_mut().pop() {
|
||||||
location
|
location
|
||||||
} else {
|
} else {
|
||||||
let data: &'static MemoryLocationInner = self.bump.alloc(MemoryLocationInner {
|
let data: &'static MemoryLocationInner = Box::leak(Box::new(MemoryLocationInner {
|
||||||
data: RefCell::new(None),
|
data: RefCell::new(None),
|
||||||
#[cfg(any(debug_assertions, feature = "check_generation"))]
|
#[cfg(any(debug_assertions, feature = "check_generation"))]
|
||||||
generation: Cell::new(0),
|
generation: Cell::new(0),
|
||||||
@@ -646,7 +642,7 @@ impl Store {
|
|||||||
borrowed_at: Default::default(),
|
borrowed_at: Default::default(),
|
||||||
#[cfg(any(debug_assertions, feature = "debug_borrows"))]
|
#[cfg(any(debug_assertions, feature = "debug_borrows"))]
|
||||||
borrowed_mut_at: Default::default(),
|
borrowed_mut_at: Default::default(),
|
||||||
});
|
}));
|
||||||
MemoryLocation(data)
|
MemoryLocation(data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user