diff --git a/components/script/dom/bindings/js.rs b/components/script/dom/bindings/js.rs index 14f717f7455..2cd327397ad 100644 --- a/components/script/dom/bindings/js.rs +++ b/components/script/dom/bindings/js.rs @@ -53,7 +53,8 @@ use js::jsapi::JSObject; use layout_interface::TrustedNodeAddress; use script_task::StackRoots; -use std::cell::{Cell, RefCell}; +use servo_util::smallvec::{SmallVec, SmallVec16}; +use std::cell::{Cell, UnsafeCell}; use std::default::Default; use std::kinds::marker::ContravariantLifetime; use std::mem; @@ -419,14 +420,14 @@ impl, U: Reflectable> TemporaryPushable for Vec> { /// An opaque, LIFO rooting mechanism. pub struct RootCollection { - roots: RefCell>, + roots: UnsafeCell>, } impl RootCollection { /// Create an empty collection of roots pub fn new() -> RootCollection { RootCollection { - roots: RefCell::new(vec!()), + roots: UnsafeCell::new(SmallVec16::new()), } } @@ -438,17 +439,23 @@ impl RootCollection { /// Track a stack-based root to ensure LIFO root ordering fn root<'a, 'b, T: Reflectable>(&self, untracked: &Root<'a, 'b, T>) { - let mut roots = self.roots.borrow_mut(); - roots.push(untracked.js_ptr); - debug!(" rooting {:?}", untracked.js_ptr); + unsafe { + let roots = self.roots.get(); + (*roots).push(untracked.js_ptr); + debug!(" rooting {:?}", untracked.js_ptr); + } } /// Stop tracking a stack-based root, asserting if LIFO root ordering has been violated fn unroot<'a, 'b, T: Reflectable>(&self, rooted: &Root<'a, 'b, T>) { - let mut roots = self.roots.borrow_mut(); - debug!("unrooting {:?} (expecting {:?}", roots.last().unwrap(), rooted.js_ptr); - assert!(*roots.last().unwrap() == rooted.js_ptr); - roots.pop().unwrap(); + unsafe { + let roots = self.roots.get(); + debug!("unrooting {:?} (expecting {:?}", + (*roots).as_slice().last().unwrap(), + rooted.js_ptr); + assert!(*(*roots).as_slice().last().unwrap() == rooted.js_ptr); + (*roots).pop().unwrap(); + } } }