Skip to content

Commit

Permalink
style: Make CASCADE_PROPERTY a real static array.
Browse files Browse the repository at this point in the history
Why wasn't this done before?
  • Loading branch information
emilio committed Jun 30, 2016
1 parent d3a1a4e commit 2faaf95
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 24 deletions.
25 changes: 9 additions & 16 deletions components/style/properties/properties.mako.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1275,7 +1275,7 @@ pub trait ComputedValues : Debug + Clone + Send + Sync + 'static {

fn initial_values() -> &'static Self;

fn do_cascade_property<F: FnOnce(&Vec<CascadePropertyFn<Self>>)>(f: F);
fn do_cascade_property<F: FnOnce(&[CascadePropertyFn<Self>])>(f: F);

% for style_struct in data.active_style_structs():
fn clone_${style_struct.trait_name_lower}(&self) ->
Expand Down Expand Up @@ -1346,8 +1346,9 @@ impl ComputedValues for ServoComputedValues {

fn initial_values() -> &'static Self { &*INITIAL_SERVO_VALUES }

fn do_cascade_property<F: FnOnce(&Vec<CascadePropertyFn<Self>>)>(f: F) {
CASCADE_PROPERTY.with(|x| f(x));
#[inline]
fn do_cascade_property<F: FnOnce(&[CascadePropertyFn<Self>])>(f: F) {
f(&CASCADE_PROPERTY)
}

% for style_struct in data.active_style_structs():
Expand Down Expand Up @@ -1747,19 +1748,11 @@ pub type CascadePropertyFn<C /*: ComputedValues */> =
cacheable: &mut bool,
error_reporter: &mut StdBox<ParseErrorReporter + Send>);

pub fn make_cascade_vec<C: ComputedValues>() -> Vec<CascadePropertyFn<C>> {
vec![
% for property in data.longhands:
longhands::${property.ident}::cascade_property,
% endfor
]
}

// This is a thread-local rather than a lazy static to avoid atomic operations when cascading
// properties.
thread_local!(static CASCADE_PROPERTY: Vec<CascadePropertyFn<ServoComputedValues>> = {
make_cascade_vec::<ServoComputedValues>()
});
static CASCADE_PROPERTY: [CascadePropertyFn<ServoComputedValues>; ${len(data.longhands)}] = [
% for property in data.longhands:
longhands::${property.ident}::cascade_property,
% endfor
];

/// Performs the CSS cascade, computing new styles for an element from its parent style and
/// optionally a cached related style. The arguments are:
Expand Down
16 changes: 8 additions & 8 deletions ports/geckolib/properties.mako.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ use style::custom_properties::ComputedValuesMap;
use style::logical_geometry::WritingMode;
use style::properties::{CascadePropertyFn, ServoComputedValues, ComputedValues};
use style::properties::longhands;
use style::properties::make_cascade_vec;
use style::properties::style_struct_traits::*;
use values::{StyleCoordHelpers, ToGeckoStyleCoord, convert_nscolor_to_rgba};
use values::{convert_rgba_to_nscolor, debug_assert_unit_is_safe_to_copy};
Expand Down Expand Up @@ -106,8 +105,9 @@ impl ComputedValues for GeckoComputedValues {

fn initial_values() -> &'static Self { &*INITIAL_GECKO_VALUES }

fn do_cascade_property<F: FnOnce(&Vec<CascadePropertyFn<Self>>)>(f: F) {
CASCADE_PROPERTY.with(|x| f(x));
#[inline]
fn do_cascade_property<F: FnOnce(&[CascadePropertyFn<Self>])>(f: F) {
f(&CASCADE_PROPERTY)
}

% for style_struct in data.style_structs:
Expand Down Expand Up @@ -1139,8 +1139,8 @@ lazy_static! {
};
}

// This is a thread-local rather than a lazy static to avoid atomic operations when cascading
// properties.
thread_local!(static CASCADE_PROPERTY: Vec<CascadePropertyFn<GeckoComputedValues>> = {
make_cascade_vec::<GeckoComputedValues>()
});
static CASCADE_PROPERTY: [CascadePropertyFn<GeckoComputedValues>; ${len(data.longhands)}] = [
% for property in data.longhands:
longhands::${property.ident}::cascade_property,
% endfor
];

0 comments on commit 2faaf95

Please sign in to comment.