mirror of
https://github.com/servo/servo.git
synced 2025-09-27 23:30:08 +01:00
script_bindings: Remove Cell wrapper from thread-local RootCollection. (#39043)
This doesn't appear to make a big difference in speedometer results, but this removes some code from the hot path of creating DomRoot values. Before: `Score: 30.381097406624708 ± 2.0393225244958018` After: `Score: 30.344639420871395 ± 1.9359337921154696` Testing: Existing WPT coverage Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
parent
d3c5a8ec15
commit
0481477f35
6 changed files with 9 additions and 37 deletions
|
@ -2,7 +2,7 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::cell::{Cell, UnsafeCell};
|
||||
use std::cell::UnsafeCell;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::ops::Deref;
|
||||
use std::{fmt, mem, ptr};
|
||||
|
@ -40,9 +40,8 @@ where
|
|||
unsafe fn add_to_root_list(object: *const dyn JSTraceable) -> *const RootCollection {
|
||||
assert_in_script();
|
||||
STACK_ROOTS.with(|root_list| {
|
||||
let root_list = unsafe { &*root_list.get().unwrap() };
|
||||
unsafe { root_list.root(object) };
|
||||
root_list
|
||||
root_list as *const _
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -390,8 +389,7 @@ pub struct RootCollection {
|
|||
impl RootCollection {
|
||||
/// Create an empty collection of roots
|
||||
#[allow(clippy::new_without_default)]
|
||||
pub fn new() -> RootCollection {
|
||||
assert_in_script();
|
||||
pub const fn new() -> RootCollection {
|
||||
RootCollection {
|
||||
roots: UnsafeCell::new(vec![]),
|
||||
}
|
||||
|
@ -419,7 +417,7 @@ impl RootCollection {
|
|||
}
|
||||
}
|
||||
|
||||
thread_local!(pub static STACK_ROOTS: Cell<Option<*const RootCollection>> = const { Cell::new(None) });
|
||||
thread_local!(pub static STACK_ROOTS: RootCollection = const { RootCollection::new() });
|
||||
|
||||
/// SM Callback that traces the rooted reflectors
|
||||
///
|
||||
|
@ -428,7 +426,7 @@ thread_local!(pub static STACK_ROOTS: Cell<Option<*const RootCollection>> = cons
|
|||
pub unsafe fn trace_roots(tracer: *mut JSTracer) {
|
||||
trace!("tracing stack roots");
|
||||
STACK_ROOTS.with(|collection| {
|
||||
let collection = unsafe { &*(*collection.get().unwrap()).roots.get() };
|
||||
let collection = unsafe { &*collection.roots.get() };
|
||||
for root in collection {
|
||||
unsafe {
|
||||
(**root).trace(tracer);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue