Bläddra i källkod

don't-box-scopestates

Evan Almloff 2 år sedan
förälder
incheckning
ba79d4babd

+ 1 - 1
packages/core/src/arena.rs

@@ -99,7 +99,7 @@ impl VirtualDom {
         self.ensure_drop_safety(id);
         self.ensure_drop_safety(id);
 
 
         if recursive {
         if recursive {
-            if let Some(root) = self.scopes[id.0].as_ref().try_root_node() {
+            if let Some(root) = self.scopes[id.0].try_root_node() {
                 if let RenderReturn::Ready(node) = unsafe { root.extend_lifetime_ref() } {
                 if let RenderReturn::Ready(node) = unsafe { root.extend_lifetime_ref() } {
                     self.drop_scope_inner(node)
                     self.drop_scope_inner(node)
                 }
                 }

+ 3 - 3
packages/core/src/scope_arena.rs

@@ -26,7 +26,7 @@ impl VirtualDom {
         let height = unsafe { parent.map(|f| (*f).height + 1).unwrap_or(0) };
         let height = unsafe { parent.map(|f| (*f).height + 1).unwrap_or(0) };
         let id = ScopeId(entry.key());
         let id = ScopeId(entry.key());
 
 
-        entry.insert(Box::new(ScopeState {
+        entry.insert(ScopeState {
             parent,
             parent,
             id,
             id,
             height,
             height,
@@ -44,13 +44,13 @@ impl VirtualDom {
             shared_contexts: Default::default(),
             shared_contexts: Default::default(),
             borrowed_props: Default::default(),
             borrowed_props: Default::default(),
             attributes_to_drop: Default::default(),
             attributes_to_drop: Default::default(),
-        }))
+        })
     }
     }
 
 
     fn acquire_current_scope_raw(&self) -> Option<*const ScopeState> {
     fn acquire_current_scope_raw(&self) -> Option<*const ScopeState> {
         let id = self.scope_stack.last().copied()?;
         let id = self.scope_stack.last().copied()?;
         let scope = self.scopes.get(id.0)?;
         let scope = self.scopes.get(id.0)?;
-        Some(scope.as_ref())
+        Some(scope)
     }
     }
 
 
     pub(crate) fn run_scope(&mut self, scope_id: ScopeId) -> &RenderReturn {
     pub(crate) fn run_scope(&mut self, scope_id: ScopeId) -> &RenderReturn {

+ 2 - 2
packages/core/src/virtual_dom.rs

@@ -177,7 +177,7 @@ use std::{any::Any, borrow::BorrowMut, cell::Cell, collections::BTreeSet, future
 pub struct VirtualDom {
 pub struct VirtualDom {
     // Maps a template path to a map of byteindexes to templates
     // Maps a template path to a map of byteindexes to templates
     pub(crate) templates: FxHashMap<TemplateId, FxHashMap<usize, Template<'static>>>,
     pub(crate) templates: FxHashMap<TemplateId, FxHashMap<usize, Template<'static>>>,
-    pub(crate) scopes: Slab<Box<ScopeState>>,
+    pub(crate) scopes: Slab<ScopeState>,
     pub(crate) dirty_scopes: BTreeSet<DirtyScope>,
     pub(crate) dirty_scopes: BTreeSet<DirtyScope>,
     pub(crate) scheduler: Rc<Scheduler>,
     pub(crate) scheduler: Rc<Scheduler>,
 
 
@@ -291,7 +291,7 @@ impl VirtualDom {
     ///
     ///
     /// This is useful for inserting or removing contexts from a scope, or rendering out its root node
     /// This is useful for inserting or removing contexts from a scope, or rendering out its root node
     pub fn get_scope(&self, id: ScopeId) -> Option<&ScopeState> {
     pub fn get_scope(&self, id: ScopeId) -> Option<&ScopeState> {
-        self.scopes.get(id.0).map(|f| f.as_ref())
+        self.scopes.get(id.0)
     }
     }
 
 
     /// Get the single scope at the top of the VirtualDom tree that will always be around
     /// Get the single scope at the top of the VirtualDom tree that will always be around