From eeefdd6cf71531fc116fc791d8e390e34cc92f04 Mon Sep 17 00:00:00 2001
From: Adoo <Adoo@outlook.com>
Date: Mon, 11 Sep 2023 12:26:10 +0800
Subject: [PATCH] =?UTF-8?q?refactor(core):=20=F0=9F=92=A1=20remove=20Rende?=
 =?UTF-8?q?rNodeFlag?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 core/src/context/build_context.rs |  9 +--------
 core/src/widget_tree/widget_id.rs | 28 ++--------------------------
 2 files changed, 3 insertions(+), 34 deletions(-)

diff --git a/core/src/context/build_context.rs b/core/src/context/build_context.rs
index 6af648750..11f9eb8ef 100644
--- a/core/src/context/build_context.rs
+++ b/core/src/context/build_context.rs
@@ -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::{
@@ -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); }
@@ -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::*;
diff --git a/core/src/widget_tree/widget_id.rs b/core/src/widget_tree/widget_id.rs
index 7e60b1c67..2f94c91be 100644
--- a/core/src/widget_tree/widget_id.rs
+++ b/core/src/widget_tree/widget_id.rs
@@ -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>,
 }
 
@@ -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(
@@ -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)) }