mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Kill RootCollectionPtr
This commit is contained in:
parent
378babfd4c
commit
b441f8a0f7
1 changed files with 4 additions and 15 deletions
|
@ -91,7 +91,7 @@ impl<T: DomObject> DomRoot<T> {
|
||||||
unsafe fn new(unrooted: Dom<T>) -> DomRoot<T> {
|
unsafe fn new(unrooted: Dom<T>) -> DomRoot<T> {
|
||||||
debug_assert!(thread_state::get().is_script());
|
debug_assert!(thread_state::get().is_script());
|
||||||
STACK_ROOTS.with(|ref collection| {
|
STACK_ROOTS.with(|ref collection| {
|
||||||
let RootCollectionPtr(collection) = collection.get().unwrap();
|
let collection = collection.get().unwrap();
|
||||||
(*collection).root(unrooted.reflector());
|
(*collection).root(unrooted.reflector());
|
||||||
DomRoot {
|
DomRoot {
|
||||||
ptr: unrooted,
|
ptr: unrooted,
|
||||||
|
@ -155,24 +155,14 @@ pub struct RootCollection {
|
||||||
roots: UnsafeCell<Vec<*const Reflector>>,
|
roots: UnsafeCell<Vec<*const Reflector>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A pointer to a RootCollection, for use in global variables.
|
thread_local!(static STACK_ROOTS: Cell<Option<*const RootCollection>> = Cell::new(None));
|
||||||
struct RootCollectionPtr(pub *const RootCollection);
|
|
||||||
|
|
||||||
impl Copy for RootCollectionPtr {}
|
|
||||||
impl Clone for RootCollectionPtr {
|
|
||||||
fn clone(&self) -> RootCollectionPtr {
|
|
||||||
*self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
thread_local!(static STACK_ROOTS: Cell<Option<RootCollectionPtr>> = Cell::new(None));
|
|
||||||
|
|
||||||
pub struct ThreadLocalStackRoots<'a>(PhantomData<&'a u32>);
|
pub struct ThreadLocalStackRoots<'a>(PhantomData<&'a u32>);
|
||||||
|
|
||||||
impl<'a> ThreadLocalStackRoots<'a> {
|
impl<'a> ThreadLocalStackRoots<'a> {
|
||||||
pub fn new(roots: &'a RootCollection) -> Self {
|
pub fn new(roots: &'a RootCollection) -> Self {
|
||||||
STACK_ROOTS.with(|ref r| {
|
STACK_ROOTS.with(|ref r| {
|
||||||
r.set(Some(RootCollectionPtr(roots as *const _)))
|
r.set(Some(roots))
|
||||||
});
|
});
|
||||||
ThreadLocalStackRoots(PhantomData)
|
ThreadLocalStackRoots(PhantomData)
|
||||||
}
|
}
|
||||||
|
@ -220,8 +210,7 @@ impl RootCollection {
|
||||||
pub unsafe fn trace_roots(tracer: *mut JSTracer) {
|
pub unsafe fn trace_roots(tracer: *mut JSTracer) {
|
||||||
debug!("tracing stack roots");
|
debug!("tracing stack roots");
|
||||||
STACK_ROOTS.with(|ref collection| {
|
STACK_ROOTS.with(|ref collection| {
|
||||||
let RootCollectionPtr(collection) = collection.get().unwrap();
|
let collection = &*(*collection.get().unwrap()).roots.get();
|
||||||
let collection = &*(*collection).roots.get();
|
|
||||||
for root in collection {
|
for root in collection {
|
||||||
trace_reflector(tracer, "on stack", &**root);
|
trace_reflector(tracer, "on stack", &**root);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue