feat: bless up, no more segfaults
This commit is contained in:
1 parent
7dfe89c958
commit
4a0068f099
14 files changed
+548
-274
No files matched your search
@@ -14,7 +14,7 @@ pub struct BumpFrame {
|
||||
pub bump: Bump,
|
||||
pub head_node: VNode<'static>,
|
||||
|
||||
#[cfg(test)]
|
||||
// used internally for debugging
|
||||
name: &'static str,
|
||||
}
|
||||
|
||||
@@ -23,16 +23,12 @@ impl ActiveFrame {
|
||||
let frame_a = BumpFrame {
|
||||
bump: Bump::new(),
|
||||
head_node: NodeFactory::unstable_place_holder(),
|
||||
|
||||
#[cfg(test)]
|
||||
name: "old",
|
||||
name: "wip",
|
||||
};
|
||||
let frame_b = BumpFrame {
|
||||
bump: Bump::new(),
|
||||
head_node: NodeFactory::unstable_place_holder(),
|
||||
|
||||
#[cfg(test)]
|
||||
name: "new",
|
||||
name: "fin",
|
||||
};
|
||||
Self {
|
||||
generation: 0.into(),
|
||||
@@ -40,42 +36,44 @@ impl ActiveFrame {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn prev_frame(&self) -> &BumpFrame {
|
||||
/// The "work in progress frame" represents the frame that is currently being worked on.
|
||||
pub fn wip_frame(&self) -> &BumpFrame {
|
||||
match self.generation.get() & 1 == 0 {
|
||||
true => &self.frames[0],
|
||||
false => &self.frames[1],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn prev_frame_mut(&mut self) -> &mut BumpFrame {
|
||||
pub fn wip_frame_mut(&mut self) -> &mut BumpFrame {
|
||||
match self.generation.get() & 1 == 0 {
|
||||
true => &mut self.frames[0],
|
||||
false => &mut self.frames[1],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cur_frame(&self) -> &BumpFrame {
|
||||
/// The finished frame represents the frame that has been "finished" and cannot be modified again
|
||||
pub fn finished_frame(&self) -> &BumpFrame {
|
||||
match self.generation.get() & 1 == 1 {
|
||||
true => &self.frames[0],
|
||||
false => &self.frames[1],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cur_frame_mut(&mut self) -> &mut BumpFrame {
|
||||
pub fn finished_frame_mut(&mut self) -> &mut BumpFrame {
|
||||
match self.generation.get() & 1 == 1 {
|
||||
true => &mut self.frames[0],
|
||||
false => &mut self.frames[1],
|
||||
}
|
||||
}
|
||||
/// Give out our self-referential item with our own borrowed lifetime
|
||||
pub fn current_head_node<'b>(&'b self) -> &'b VNode<'b> {
|
||||
let cur_head = &self.cur_frame().head_node;
|
||||
pub fn fin_head<'b>(&'b self) -> &'b VNode<'b> {
|
||||
let cur_head = &self.finished_frame().head_node;
|
||||
unsafe { std::mem::transmute::<&VNode<'static>, &VNode<'b>>(cur_head) }
|
||||
}
|
||||
|
||||
/// Give out our self-referential item with our own borrowed lifetime
|
||||
pub fn prev_head_node<'b>(&'b self) -> &'b VNode<'b> {
|
||||
let cur_head = &self.prev_frame().head_node;
|
||||
pub fn wip_head<'b>(&'b self) -> &'b VNode<'b> {
|
||||
let cur_head = &self.wip_frame().head_node;
|
||||
unsafe { std::mem::transmute::<&VNode<'static>, &VNode<'b>>(cur_head) }
|
||||
}
|
||||
|
||||
@@ -95,16 +93,16 @@ mod tests {
|
||||
|
||||
// just cycle a few times and make sure we get the right frames out
|
||||
for _ in 0..5 {
|
||||
let old = frames.prev_frame();
|
||||
let new = frames.cur_frame();
|
||||
assert_eq!(old.name, "old");
|
||||
assert_eq!(new.name, "new");
|
||||
let fin = frames.finished_frame();
|
||||
let wip = frames.wip_frame();
|
||||
assert_eq!(wip.name, "wip");
|
||||
assert_eq!(fin.name, "fin");
|
||||
frames.cycle_frame();
|
||||
|
||||
let old = frames.prev_frame();
|
||||
let new = frames.cur_frame();
|
||||
assert_eq!(old.name, "new");
|
||||
assert_eq!(new.name, "old");
|
||||
let fin = frames.finished_frame();
|
||||
let wip = frames.wip_frame();
|
||||
assert_eq!(wip.name, "fin");
|
||||
assert_eq!(fin.name, "wip");
|
||||
frames.cycle_frame();
|
||||
}
|
||||
assert_eq!(frames.generation.get(), 10);
|
||||
|
||||
Reference in new issue
Block a user