style: Optimize cascading of other wide keywords if possible.

The way the copy-on-write stuff works, and the way that we have to apply
properties from most specific to less specific guarantees that always that we're
going to inherit an inherited property, or reset a reset property, we have
already the right value on the style.

Revert relies on that, so there doesn't seem to be a reason to not use that fact
more often and skip useless work earlier.

Font-size is still special of course... I think I have a way to move the
specialness outside of the style, but piece by piece.

Differential Revision: https://phabricator.services.mozilla.com/D21882
This commit is contained in:
Emilio Cobos Álvarez 2019-03-07 12:48:07 +00:00
parent 6fd17ccb35
commit 4a1f390788
3 changed files with 37 additions and 38 deletions

View file

@ -2117,12 +2117,6 @@ impl PropertyDeclaration {
}
}
/// Whether this declaration is the `revert` keyword.
#[inline]
pub fn is_revert(&self) -> bool {
self.get_css_wide_keyword().map_or(false, |kw| kw == CSSWideKeyword::Revert)
}
/// Returns whether or not the property is set by a system font
pub fn get_system(&self) -> Option<SystemFont> {
match *self {
@ -3447,22 +3441,16 @@ impl<'a> StyleBuilder<'a> {
}
% for property in data.longhands:
% if property.ident != "font_size":
% if not property.style_struct.inherited:
/// Inherit `${property.ident}` from our parent style.
#[allow(non_snake_case)]
pub fn inherit_${property.ident}(&mut self) {
let inherited_struct =
% if property.style_struct.inherited:
self.inherited_style.get_${property.style_struct.name_lower}();
% else:
self.inherited_style_ignoring_first_line
.get_${property.style_struct.name_lower}();
% endif
% if not property.style_struct.inherited:
self.flags.insert(ComputedValueFlags::INHERITS_RESET_STYLE);
self.modified_reset = true;
% endif
self.flags.insert(ComputedValueFlags::INHERITS_RESET_STYLE);
% if property.ident == "content":
self.flags.insert(ComputedValueFlags::INHERITS_CONTENT);
@ -3484,17 +3472,13 @@ impl<'a> StyleBuilder<'a> {
% endif
);
}
% elif property.name != "font-size":
/// Reset `${property.ident}` to the initial value.
#[allow(non_snake_case)]
pub fn reset_${property.ident}(&mut self) {
let reset_struct =
self.reset_style.get_${property.style_struct.name_lower}();
% if not property.style_struct.inherited:
self.modified_reset = true;
% endif
if self.${property.style_struct.ident}.ptr_eq(reset_struct) {
return;
}
@ -3507,6 +3491,7 @@ impl<'a> StyleBuilder<'a> {
% endif
);
}
% endif
% if not property.is_vector:
/// Set the `${property.ident}` to the computed value `value`.
@ -3528,7 +3513,6 @@ impl<'a> StyleBuilder<'a> {
);
}
% endif
% endif
% endfor
<% del property %>