style: Perform variable substitution less often.

We're wasting a bunch of work unneedlessly.
This commit is contained in:
Emilio Cobos Álvarez 2017-11-24 22:03:03 +01:00
parent 3907953d80
commit 90ba75ab44
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C

View file

@ -3276,12 +3276,6 @@ where
};
let ignore_colors = !device.use_document_colors();
let default_background_color_decl = if ignore_colors {
let color = device.default_background_color();
Some(PropertyDeclaration::BackgroundColor(color.into()))
} else {
None
};
// Set computed values, overwriting earlier declarations for the same
// property.
@ -3304,22 +3298,8 @@ where
let mut font_family = None;
% endif
for (declaration, cascade_level) in iter_declarations() {
let mut declaration = match *declaration {
PropertyDeclaration::WithVariables(id, ref unparsed) => {
if !id.inherited() {
context.rule_cache_conditions.borrow_mut()
.set_uncacheable();
}
Cow::Owned(unparsed.substitute_variables(
id,
context.builder.custom_properties.as_ref(),
context.quirks_mode
))
}
ref d => Cow::Borrowed(d)
};
let longhand_id = match declaration.id() {
let declaration_id = declaration.id();
let longhand_id = match declaration_id {
PropertyDeclarationId::Longhand(id) => id,
PropertyDeclarationId::Custom(..) => continue,
};
@ -3336,31 +3316,6 @@ where
continue;
}
// When document colors are disabled, skip properties that are
// marked as ignored in that mode, if they come from a UA or
// user style sheet.
if ignore_colors &&
longhand_id.is_ignored_when_document_colors_disabled() &&
!matches!(cascade_level,
CascadeLevel::UANormal |
CascadeLevel::UserNormal |
CascadeLevel::UserImportant |
CascadeLevel::UAImportant) {
let non_transparent_background = match *declaration {
PropertyDeclaration::BackgroundColor(ref color) => {
// Treat background-color a bit differently. If the specified
// color is anything other than a fully transparent color, convert
// it into the Device's default background color.
color.is_non_transparent()
}
_ => continue
};
// FIXME: moving this out of `match` is a work around for borrows being lexical.
if non_transparent_background {
declaration = Cow::Borrowed(default_background_color_decl.as_ref().unwrap());
}
}
if
% if category_to_cascade_now == "early":
!
@ -3377,6 +3332,50 @@ where
}
seen.insert(physical_longhand_id);
let mut declaration = match *declaration {
PropertyDeclaration::WithVariables(id, ref unparsed) => {
if !id.inherited() {
context.rule_cache_conditions.borrow_mut()
.set_uncacheable();
}
Cow::Owned(unparsed.substitute_variables(
id,
context.builder.custom_properties.as_ref(),
context.quirks_mode
))
}
ref d => Cow::Borrowed(d)
};
// When document colors are disabled, skip properties that are
// marked as ignored in that mode, unless they come from a UA or
// user style sheet.
if ignore_colors &&
longhand_id.is_ignored_when_document_colors_disabled() &&
!matches!(cascade_level,
CascadeLevel::UANormal |
CascadeLevel::UserNormal |
CascadeLevel::UserImportant |
CascadeLevel::UAImportant) {
let non_transparent_background = match *declaration {
PropertyDeclaration::BackgroundColor(ref color) => {
// Treat background-color a bit differently. If the specified
// color is anything other than a fully transparent color, convert
// it into the Device's default background color.
color.is_non_transparent()
}
_ => continue
};
// FIXME: moving this out of `match` is a work around for
// borrows being lexical.
if non_transparent_background {
let color = device.default_background_color();
declaration =
Cow::Owned(PropertyDeclaration::BackgroundColor(color.into()));
}
}
% if category_to_cascade_now == "early":
if LonghandId::FontSize == longhand_id {
font_size = Some(declaration.clone());