mirror of
https://github.com/leptos-rs/leptos
synced 2024-11-10 14:54:16 +00:00
Remove allocation in ScopeDisposer
This commit is contained in:
parent
164dcd1b97
commit
b51da35a9a
2 changed files with 6 additions and 4 deletions
|
@ -418,7 +418,7 @@ impl RuntimeId {
|
|||
with_runtime(self, |runtime| {
|
||||
let id = { runtime.scopes.borrow_mut().insert(Default::default()) };
|
||||
let scope = Scope { runtime: self, id };
|
||||
let disposer = ScopeDisposer(Box::new(move || scope.dispose()));
|
||||
let disposer = ScopeDisposer(scope);
|
||||
(scope, disposer)
|
||||
})
|
||||
.expect(
|
||||
|
@ -439,7 +439,7 @@ impl RuntimeId {
|
|||
}
|
||||
let scope = Scope { runtime: self, id };
|
||||
let val = f(scope);
|
||||
let disposer = ScopeDisposer(Box::new(move || scope.dispose()));
|
||||
let disposer = ScopeDisposer(scope);
|
||||
(val, id, disposer)
|
||||
})
|
||||
.expect("tried to run scope in a runtime that has been disposed")
|
||||
|
|
|
@ -336,7 +336,8 @@ pub(crate) enum ScopeProperty {
|
|||
/// 1. dispose of all child `Scope`s
|
||||
/// 2. run all cleanup functions defined for this scope by [on_cleanup](crate::on_cleanup).
|
||||
/// 3. dispose of all signals, effects, and resources owned by this `Scope`.
|
||||
pub struct ScopeDisposer(pub(crate) Box<dyn FnOnce()>);
|
||||
#[repr(transparent)]
|
||||
pub struct ScopeDisposer(pub(crate) Scope);
|
||||
|
||||
impl ScopeDisposer {
|
||||
/// Disposes of a reactive [Scope](crate::Scope).
|
||||
|
@ -345,8 +346,9 @@ impl ScopeDisposer {
|
|||
/// 1. dispose of all child `Scope`s
|
||||
/// 2. run all cleanup functions defined for this scope by [on_cleanup](crate::on_cleanup).
|
||||
/// 3. dispose of all signals, effects, and resources owned by this `Scope`.
|
||||
#[inline(always)]
|
||||
pub fn dispose(self) {
|
||||
(self.0)()
|
||||
self.0.dispose()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue