From 8e2acee24e58850ee32d27774cb8e7a21a9a2f02 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 4 Jan 2017 14:00:05 -0500 Subject: [PATCH] Bug 1298588 part 14. Remove ComputedValues::initial_values for stylo. r=bholley --- components/style/properties/gecko.mako.rs | 37 ----------------------- ports/geckolib/glue.rs | 14 --------- 2 files changed, 51 deletions(-) diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 6fd2d868b26..972f3aab42a 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -55,7 +55,6 @@ use properties::longhands; use std::fmt::{self, Debug}; use std::mem::{transmute, zeroed}; use std::ptr; -use std::sync::atomic::{ATOMIC_USIZE_INIT, AtomicUsize, Ordering}; use std::sync::Arc; use std::cmp; @@ -113,13 +112,6 @@ impl ComputedValues { } } - pub fn initial_values() -> &'static Self { - unsafe { - debug_assert!(!raw_initial_values().is_null()); - &*raw_initial_values() - } - } - pub fn default_values(pres_context: RawGeckoPresContextBorrowed) -> Arc { Arc::new(ComputedValues { custom_properties: None, @@ -132,25 +124,6 @@ impl ComputedValues { }) } - pub unsafe fn initialize() { - debug_assert!(raw_initial_values().is_null()); - set_raw_initial_values(Box::into_raw(Box::new(ComputedValues { - % for style_struct in data.style_structs: - ${style_struct.ident}: style_structs::${style_struct.name}::initial(), - % endfor - custom_properties: None, - shareable: true, - writing_mode: WritingMode::empty(), - root_font_size: longhands::font_size::get_initial_value(), - }))); - } - - pub unsafe fn shutdown() { - debug_assert!(!raw_initial_values().is_null()); - let _ = Box::from_raw(raw_initial_values()); - set_raw_initial_values(ptr::null_mut()); - } - % for style_struct in data.style_structs: #[inline] pub fn clone_${style_struct.name_lower}(&self) -> Arc { @@ -2662,13 +2635,3 @@ pub unsafe extern "C" fn Servo_GetStyleVariables(_cv: ServoComputedValuesBorrowe &*EMPTY_VARIABLES_STRUCT } -// To avoid UB, we store the initial values as a atomic. It would be nice to -// store them as AtomicPtr, but we can't have static AtomicPtr without const -// fns, which aren't in stable Rust. -static INITIAL_VALUES_STORAGE: AtomicUsize = ATOMIC_USIZE_INIT; -unsafe fn raw_initial_values() -> *mut ComputedValues { - INITIAL_VALUES_STORAGE.load(Ordering::Relaxed) as *mut ComputedValues -} -unsafe fn set_raw_initial_values(v: *mut ComputedValues) { - INITIAL_VALUES_STORAGE.store(v as usize, Ordering::Relaxed); -} diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index ef6bdb28ff6..aeb1fe6484e 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -82,17 +82,12 @@ pub extern "C" fn Servo_Initialize() -> () { // See https://doc.rust-lang.org/log/env_logger/index.html for instructions. env_logger::init().unwrap(); - // Allocate our default computed values. - unsafe { ComputedValues::initialize(); } - // Pretend that we're a Servo Layout thread, to make some assertions happy. thread_state::initialize(thread_state::LAYOUT); } #[no_mangle] pub extern "C" fn Servo_Shutdown() -> () { - // Destroy our default computed values. - unsafe { ComputedValues::shutdown(); } } fn create_shared_context(per_doc_data: &PerDocumentStyleDataImpl) -> SharedStyleContext { @@ -118,15 +113,6 @@ fn create_shared_context(per_doc_data: &PerDocumentStyleDataImpl) -> SharedStyle fn traverse_subtree(element: GeckoElement, raw_data: RawServoStyleSetBorrowed, unstyled_children_only: bool) { - // Force the creation of our lazily-constructed initial computed values on - // the main thread, since it's not safe to call elsewhere. - // - // FIXME(bholley): this should move into Servo_Initialize as soon as we get - // rid of the HackilyFindSomeDeviceContext stuff that happens during - // initial_values computation, since that stuff needs to be called further - // along in startup than the sensible place to call Servo_Initialize. - ComputedValues::initial_values(); - // When new content is inserted in a display:none subtree, we will call into // servo to try to style it. Detect that here and bail out. if let Some(parent) = element.parent_element() {