mirror of
https://github.com/servo/servo.git
synced 2025-07-26 00:30:22 +01:00
script: Use a 16-element SmallVec
for the root collection.
In my tests the size of the root collection never exceeded 7, so 16 seems like a nice conservative number.
This commit is contained in:
parent
541077286c
commit
5e9127e2b2
1 changed files with 17 additions and 10 deletions
|
@ -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<T: Assignable<U>, U: Reflectable> TemporaryPushable<T> for Vec<JS<U>> {
|
|||
|
||||
/// An opaque, LIFO rooting mechanism.
|
||||
pub struct RootCollection {
|
||||
roots: RefCell<Vec<*mut JSObject>>,
|
||||
roots: UnsafeCell<SmallVec16<*mut JSObject>>,
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue