-
-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
71 additions
and
27 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
boa_engine/src/object/shape/shared_shape/forward_transition.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use std::hash::Hash; | ||
|
||
use boa_gc::{Finalize, Gc, GcRefCell, Trace, WeakGc}; | ||
use rustc_hash::FxHashMap; | ||
|
||
use super::Inner as SharedShapeInner; | ||
|
||
/// Holds a forward reference to a previously created transition. | ||
/// The reference is weak, therefore it can be garbage collected if it is not in use. | ||
#[derive(Debug, Clone, Trace, Finalize)] | ||
pub(super) struct ForwardTransition<T: Hash + Eq + Trace + 'static> { | ||
transitions: GcRefCell<FxHashMap<T, WeakGc<SharedShapeInner>>>, | ||
} | ||
|
||
impl<T: Hash + Eq + Trace + 'static> Default for ForwardTransition<T> { | ||
fn default() -> Self { | ||
Self { | ||
transitions: GcRefCell::default(), | ||
} | ||
} | ||
} | ||
|
||
impl<T: Hash + Eq + Trace + 'static> ForwardTransition<T> { | ||
pub(super) fn insert(&self, key: T, value: &Gc<SharedShapeInner>) { | ||
let mut transitions = self.transitions.borrow_mut(); | ||
transitions.insert(key, WeakGc::new(value)); | ||
} | ||
pub(super) fn get(&self, key: &T) -> Option<WeakGc<SharedShapeInner>> { | ||
let transitions = self.transitions.borrow(); | ||
transitions.get(key).cloned() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters