Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a replacement for Vec<Root<T>> #4620

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Prev

Address review comments.

  • Loading branch information
jdm committed Mar 1, 2015
commit 0cda230d535e73e8b9723109dcac735ecb9df2ac
@@ -267,7 +267,7 @@ impl JSTraceable for Box<LayoutRPC+'static> {

/// Holds a set of vectors that need to be rooted
pub struct RootedCollectionSet {
set: Vec<HashSet<*const ()>>
set: Vec<HashSet<*const RootedVec<()>>>
}

/// TLV Holds a set of vectors that need to be rooted
@@ -288,11 +288,11 @@ impl RootedCollectionSet {
}
}

fn remove<T: VecRootableType>(collection: &mut RootedVec<T>) {
fn remove<T: VecRootableType>(collection: &RootedVec<T>) {
ROOTED_COLLECTIONS.with(|ref collections| {
let type_ = VecRootableType::tag(None::<T>);
let mut collections = collections.borrow_mut();
assert!(collections.set[type_ as uint].remove(&(collection as *mut _ as *const _)));
assert!(collections.set[type_ as uint].remove(&(collection as *const _ as *const _)));
});
}

@@ -306,9 +306,10 @@ impl RootedCollectionSet {

unsafe fn trace(&self, tracer: *mut JSTracer) {
fn trace_collection_type<T: JSTraceable>(tracer: *mut JSTracer,
collections: *const HashSet<*const RootedVec<T>>) {
unsafe {
for collection in (*collections).iter() {
collections: &HashSet<*const RootedVec<()>>) {
for collection in collections.iter() {
let collection = &(*collection as *const RootedVec<T>);
unsafe {
let _ = (**collection).trace(tracer);
}
}
@@ -321,10 +322,8 @@ impl RootedCollectionSet {
}
}

trace_collection_type(tracer,
&self.set[CollectionType::JSVals as uint] as *const _ as *const HashSet<*const RootedVec<JSVal>>);
trace_collection_type(tracer,
&self.set[CollectionType::JSObjects as uint] as *const _ as *const HashSet<*const RootedVec<*mut JSObject>>);
trace_collection_type::<JSVal>(tracer, &self.set[CollectionType::JSVals as uint]);
trace_collection_type::<*mut JSObject>(tracer, &self.set[CollectionType::JSObjects as uint]);
}
}

@@ -360,11 +359,10 @@ impl<T: VecRootableType> RootedVec<T> {
/// Create a vector of items of type T that is rooted for
/// the lifetime of this struct
pub fn new() -> RootedVec<T> {
let ret = RootedVec::<T> { v: vec!() };
unsafe {
RootedCollectionSet::add::<T>(&*(return_address() as *const _));
}
ret
RootedVec::<T> { v: vec!() }
}

}
@@ -381,7 +381,6 @@ impl ScriptTask {

pub fn new_rt_and_cx() -> (js::rust::rt, Rc<Cx>) {
LiveDOMReferences::initialize();

let js_runtime = js::rust::rt();
assert!({
let ptr: *mut JSRuntime = (*js_runtime).ptr;
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.