Skip to content

Commit

Permalink
refactor(core): 💡 remove RenderNodeFlag
Browse files Browse the repository at this point in the history
  • Loading branch information
M-Adoo committed Sep 12, 2023
1 parent 45e9357 commit eeefdd6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 34 deletions.
9 changes: 1 addition & 8 deletions core/src/context/build_context.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
prelude::*,
widget::{widget_id::new_node, TreeArena, WidgetTree},
widget::{widget_id::new_node, WidgetTree},
window::{DelayEvent, WindowId},
};
use std::{
Expand Down Expand Up @@ -122,8 +122,6 @@ impl<'a> BuildCtx<'a> {
tree
.window()
.add_delay_event(DelayEvent::Disposed { id, parent });
let (arena1, arena2) = unsafe { split_arena(&mut tree.arena) };
id.descendants(arena1).for_each(|id| id.mark_drop(arena2))
}

pub(crate) fn mark_dirty(&mut self, id: WidgetId) { self.tree.borrow_mut().mark_dirty(id); }
Expand Down Expand Up @@ -180,11 +178,6 @@ impl BuildCtxHandle {
}
}

pub(crate) unsafe fn split_arena(tree: &mut TreeArena) -> (&mut TreeArena, &mut TreeArena) {
let ptr = tree as *mut TreeArena;
(&mut *ptr, &mut *ptr)
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
28 changes: 2 additions & 26 deletions core/src/widget_tree/widget_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,7 @@ pub struct WidgetId(pub(crate) NodeId);

pub(crate) type TreeArena = Arena<RenderNode>;

bitflags! {
#[derive(Default, PartialEq, Eq, Clone, Copy, Hash, Debug)]
pub(crate) struct RenderNodeFlag: u8 {
const NONE = 0;
const DROPPED = 0b0001;
}
}
pub(crate) struct RenderNode {
flags: RenderNodeFlag,
data: Box<dyn Render>,
}

Expand All @@ -47,21 +39,8 @@ impl WidgetId {
tree.get_mut(self.0).map(|n| n.get_mut())
}

/// Mark the widget dropped but not release the node, caller has the
/// responsibility to release it.
pub(crate) fn mark_drop(self, tree: &mut TreeArena) {
if let Some(node) = self.get_node_mut(tree) {
node.flags.insert(RenderNodeFlag::DROPPED);
}
}

/// detect if the widget of this id point to is dropped.
pub(crate) fn is_dropped(self, tree: &TreeArena) -> bool {
self.0.is_removed(tree)
|| self
.get_node(tree)
.map_or(true, |n| n.flags.contains(RenderNodeFlag::DROPPED))
}
pub(crate) fn is_dropped(self, tree: &TreeArena) -> bool { self.0.is_removed(tree) }

#[allow(clippy::needless_collect)]
pub(crate) fn lowest_common_ancestor(
Expand Down Expand Up @@ -234,10 +213,7 @@ impl WidgetId {
}

pub(crate) fn new_node(arena: &mut TreeArena, node: Box<dyn Render>) -> WidgetId {
WidgetId(arena.new_node(RenderNode {
flags: RenderNodeFlag::NONE,
data: node,
}))
WidgetId(arena.new_node(RenderNode { data: node }))
}

pub(crate) fn empty_node(arena: &mut TreeArena) -> WidgetId { new_node(arena, Box::new(Void)) }
Expand Down

0 comments on commit eeefdd6

Please sign in to comment.