Keep track of the number of important and normal declarations in a block

… instead of the presence (`bool` flags) of each.

This allows removing `recalc_any` which iterated over the `Vec`.
This commit is contained in:
Simon Sapin 2016-08-21 03:20:29 +02:00
parent 5e4bdac2bd
commit f9150af936
5 changed files with 107 additions and 70 deletions

View file

@ -46,8 +46,10 @@ fn property_declaration_block_should_serialize_correctly() {
let block = PropertyDeclarationBlock {
declarations: Arc::new(declarations),
any_important: true,
any_normal: true,
// Incorrect, but not used here:
normal_count: 0,
important_count: 0,
};
let css_string = block.to_css_string();
@ -64,8 +66,10 @@ mod shorthand_serialization {
pub fn shorthand_properties_to_string(properties: Vec<PropertyDeclaration>) -> String {
let block = PropertyDeclarationBlock {
declarations: Arc::new(properties.into_iter().map(|d| (d, Importance::Normal)).collect()),
any_important: false,
any_normal: true,
// Incorrect, but not used here:
normal_count: 0,
important_count: 0,
};
block.to_css_string()

View file

@ -24,8 +24,18 @@ fn test_parse_stylesheet() {
let css = r"
@namespace url(http://www.w3.org/1999/xhtml);
/* FIXME: only if scripting is enabled */
input[type=hidden i] { display: none !important; }
html , body /**/ { display: block; }
input[type=hidden i] {
display: block !important;
display: none !important;
display: inline;
--a: b !important;
--a: inherit !important;
--a: c;
}
html , body /**/ {
display: none;
display: block;
}
#d1 > .ok { background: blue; }
@keyframes foo {
from { width: 0% }
@ -92,9 +102,11 @@ fn test_parse_stylesheet() {
(PropertyDeclaration::Display(DeclaredValue::Value(
longhands::display::SpecifiedValue::none)),
Importance::Important),
(PropertyDeclaration::Custom(Atom::from("a"), DeclaredValue::Inherit),
Importance::Important),
]),
any_normal: false,
any_important: true,
normal_count: 0,
important_count: 2,
},
}),
CSSRule::Style(StyleRule {
@ -140,8 +152,8 @@ fn test_parse_stylesheet() {
longhands::display::SpecifiedValue::block)),
Importance::Normal),
]),
any_normal: true,
any_important: false,
normal_count: 1,
important_count: 0,
},
}),
CSSRule::Style(StyleRule {
@ -196,8 +208,8 @@ fn test_parse_stylesheet() {
(PropertyDeclaration::BackgroundClip(DeclaredValue::Initial),
Importance::Normal),
]),
any_normal: true,
any_important: false,
normal_count: 8,
important_count: 0,
},
}),
CSSRule::Keyframes(KeyframesRule {