Bug 1298588 part 14. Remove ComputedValues::initial_values for stylo. r=bholley

This commit is contained in:
Boris Zbarsky 2017-01-04 14:00:05 -05:00
parent 369fdddcd9
commit 8e2acee24e
2 changed files with 0 additions and 51 deletions

View file

@ -55,7 +55,6 @@ use properties::longhands;
use std::fmt::{self, Debug}; use std::fmt::{self, Debug};
use std::mem::{transmute, zeroed}; use std::mem::{transmute, zeroed};
use std::ptr; use std::ptr;
use std::sync::atomic::{ATOMIC_USIZE_INIT, AtomicUsize, Ordering};
use std::sync::Arc; use std::sync::Arc;
use std::cmp; 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<Self> { pub fn default_values(pres_context: RawGeckoPresContextBorrowed) -> Arc<Self> {
Arc::new(ComputedValues { Arc::new(ComputedValues {
custom_properties: None, 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: % for style_struct in data.style_structs:
#[inline] #[inline]
pub fn clone_${style_struct.name_lower}(&self) -> Arc<style_structs::${style_struct.name}> { pub fn clone_${style_struct.name_lower}(&self) -> Arc<style_structs::${style_struct.name}> {
@ -2662,13 +2635,3 @@ pub unsafe extern "C" fn Servo_GetStyleVariables(_cv: ServoComputedValuesBorrowe
&*EMPTY_VARIABLES_STRUCT &*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);
}

View file

@ -82,17 +82,12 @@ pub extern "C" fn Servo_Initialize() -> () {
// See https://doc.rust-lang.org/log/env_logger/index.html for instructions. // See https://doc.rust-lang.org/log/env_logger/index.html for instructions.
env_logger::init().unwrap(); 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. // Pretend that we're a Servo Layout thread, to make some assertions happy.
thread_state::initialize(thread_state::LAYOUT); thread_state::initialize(thread_state::LAYOUT);
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn Servo_Shutdown() -> () { pub extern "C" fn Servo_Shutdown() -> () {
// Destroy our default computed values.
unsafe { ComputedValues::shutdown(); }
} }
fn create_shared_context(per_doc_data: &PerDocumentStyleDataImpl) -> SharedStyleContext { 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, fn traverse_subtree(element: GeckoElement, raw_data: RawServoStyleSetBorrowed,
unstyled_children_only: bool) { 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 // 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. // servo to try to style it. Detect that here and bail out.
if let Some(parent) = element.parent_element() { if let Some(parent) = element.parent_element() {