Skip to content

Commit c28716e

Browse files
committed
Optimized the code structure of cache-related functions.
1 parent 8848a72 commit c28716e

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

cache/src/cache.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ const CACHE_CAP: usize = 128;
1313
static mut CACHE: Lazy<LruCache<CacheKey, Rc<dyn Any>>> =
1414
Lazy::new(|| LruCache::new(NonZeroUsize::new(CACHE_CAP).unwrap()));
1515

16-
pub(crate) fn touch<T: 'static>(key: &'static dyn Observable) -> Option<Rc<T>> {
16+
pub(crate) fn touch<T>(key: &'static dyn Observable) -> Option<Rc<T>>
17+
where
18+
T: 'static,
19+
{
1720
// When the Effect performs dependency calculations for the first time,
1821
// it must ignore the relevant cache,
1922
// otherwise the underlying Signal will not remember the Effect.
@@ -28,7 +31,10 @@ pub(crate) fn touch<T: 'static>(key: &'static dyn Observable) -> Option<Rc<T>> {
2831
.map(|rc| unsafe { Rc::from_raw(Rc::into_raw(rc) as *const T) })
2932
}
3033

31-
pub(crate) fn store_in_cache<T: 'static>(key: &'static dyn Observable, val: T) -> Rc<T> {
34+
pub(crate) fn store_in_cache<T>(key: &'static dyn Observable, val: T) -> Rc<T>
35+
where
36+
T: 'static,
37+
{
3238
let rc = Rc::new(val);
3339
unsafe { CACHE.put(key, Rc::clone(&rc) as _) };
3440
rc

macros/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ pub fn memo(_attr: TokenStream, item: TokenStream) -> TokenStream {
183183
static mut #ident: #ty = #expr;
184184

185185
#vis #sig
186-
where #output_ty: Clone + 'static
186+
where #output_ty: Clone
187187
{
188188
unsafe { (*#ident).get() }
189189
}

0 commit comments

Comments
 (0)