mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
Track only the number of important declarations in a declaration block
This commit is contained in:
parent
daee53cb76
commit
908b9627a2
5 changed files with 8 additions and 33 deletions
|
@ -774,8 +774,6 @@ impl Element {
|
||||||
Arc::make_mut(&mut declarations.declarations).remove(index);
|
Arc::make_mut(&mut declarations.declarations).remove(index);
|
||||||
if importance.unwrap().important() {
|
if importance.unwrap().important() {
|
||||||
declarations.important_count -= 1;
|
declarations.important_count -= 1;
|
||||||
} else {
|
|
||||||
declarations.normal_count -= 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -802,11 +800,9 @@ impl Element {
|
||||||
if existing_declaration.0.name() == incoming_declaration.name() {
|
if existing_declaration.0.name() == incoming_declaration.name() {
|
||||||
match (existing_declaration.1, importance) {
|
match (existing_declaration.1, importance) {
|
||||||
(Importance::Normal, Importance::Important) => {
|
(Importance::Normal, Importance::Important) => {
|
||||||
declaration_block.normal_count -= 1;
|
|
||||||
declaration_block.important_count += 1;
|
declaration_block.important_count += 1;
|
||||||
}
|
}
|
||||||
(Importance::Important, Importance::Normal) => {
|
(Importance::Important, Importance::Normal) => {
|
||||||
declaration_block.normal_count += 1;
|
|
||||||
declaration_block.important_count -= 1;
|
declaration_block.important_count -= 1;
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
@ -818,23 +814,20 @@ impl Element {
|
||||||
existing_declarations.push((incoming_declaration, importance));
|
existing_declarations.push((incoming_declaration, importance));
|
||||||
if importance.important() {
|
if importance.important() {
|
||||||
declaration_block.important_count += 1;
|
declaration_block.important_count += 1;
|
||||||
} else {
|
|
||||||
declaration_block.normal_count += 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let (normal_count, important_count) = if importance.important() {
|
let important_count = if importance.important() {
|
||||||
(0, declarations.len() as u32)
|
declarations.len() as u32
|
||||||
} else {
|
} else {
|
||||||
(declarations.len() as u32, 0)
|
0
|
||||||
};
|
};
|
||||||
|
|
||||||
*inline_declarations = Some(PropertyDeclarationBlock {
|
*inline_declarations = Some(PropertyDeclarationBlock {
|
||||||
declarations: Arc::new(declarations.into_iter().map(|d| (d, importance)).collect()),
|
declarations: Arc::new(declarations.into_iter().map(|d| (d, importance)).collect()),
|
||||||
normal_count: normal_count,
|
|
||||||
important_count: important_count,
|
important_count: important_count,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -856,11 +849,9 @@ impl Element {
|
||||||
if properties.iter().any(|p| declaration.name() == **p) {
|
if properties.iter().any(|p| declaration.name() == **p) {
|
||||||
match (*importance, new_importance) {
|
match (*importance, new_importance) {
|
||||||
(Importance::Normal, Importance::Important) => {
|
(Importance::Normal, Importance::Important) => {
|
||||||
block.normal_count -= 1;
|
|
||||||
block.important_count += 1;
|
block.important_count += 1;
|
||||||
}
|
}
|
||||||
(Importance::Important, Importance::Normal) => {
|
(Importance::Important, Importance::Normal) => {
|
||||||
block.normal_count += 1;
|
|
||||||
block.important_count -= 1;
|
block.important_count -= 1;
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|
|
@ -288,9 +288,6 @@ pub struct PropertyDeclarationBlock {
|
||||||
#[cfg_attr(feature = "servo", ignore_heap_size_of = "#7038")]
|
#[cfg_attr(feature = "servo", ignore_heap_size_of = "#7038")]
|
||||||
pub declarations: Arc<Vec<(PropertyDeclaration, Importance)>>,
|
pub declarations: Arc<Vec<(PropertyDeclaration, Importance)>>,
|
||||||
|
|
||||||
/// The number of entries in `self.declaration` with `Importance::Normal`
|
|
||||||
pub normal_count: u32,
|
|
||||||
|
|
||||||
/// The number of entries in `self.declaration` with `Importance::Important`
|
/// The number of entries in `self.declaration` with `Importance::Important`
|
||||||
pub important_count: u32,
|
pub important_count: u32,
|
||||||
}
|
}
|
||||||
|
@ -548,7 +545,6 @@ impl<'a, 'b> DeclarationParser for PropertyDeclarationParser<'a, 'b> {
|
||||||
pub fn parse_property_declaration_list(context: &ParserContext, input: &mut Parser)
|
pub fn parse_property_declaration_list(context: &ParserContext, input: &mut Parser)
|
||||||
-> PropertyDeclarationBlock {
|
-> PropertyDeclarationBlock {
|
||||||
let mut declarations = Vec::new();
|
let mut declarations = Vec::new();
|
||||||
let mut normal_count = 0;
|
|
||||||
let mut important_count = 0;
|
let mut important_count = 0;
|
||||||
let parser = PropertyDeclarationParser {
|
let parser = PropertyDeclarationParser {
|
||||||
context: context,
|
context: context,
|
||||||
|
@ -559,8 +555,6 @@ pub fn parse_property_declaration_list(context: &ParserContext, input: &mut Pars
|
||||||
Ok((results, importance)) => {
|
Ok((results, importance)) => {
|
||||||
if importance.important() {
|
if importance.important() {
|
||||||
important_count += results.len() as u32;
|
important_count += results.len() as u32;
|
||||||
} else {
|
|
||||||
normal_count += results.len() as u32;
|
|
||||||
}
|
}
|
||||||
declarations.extend(results.into_iter().map(|d| (d, importance)))
|
declarations.extend(results.into_iter().map(|d| (d, importance)))
|
||||||
}
|
}
|
||||||
|
@ -574,7 +568,6 @@ pub fn parse_property_declaration_list(context: &ParserContext, input: &mut Pars
|
||||||
}
|
}
|
||||||
let mut block = PropertyDeclarationBlock {
|
let mut block = PropertyDeclarationBlock {
|
||||||
declarations: Arc::new(declarations),
|
declarations: Arc::new(declarations),
|
||||||
normal_count: normal_count,
|
|
||||||
important_count: important_count,
|
important_count: important_count,
|
||||||
};
|
};
|
||||||
deduplicate_property_declarations(&mut block);
|
deduplicate_property_declarations(&mut block);
|
||||||
|
@ -605,13 +598,11 @@ fn deduplicate_property_declarations(block: &mut PropertyDeclarationBlock) {
|
||||||
remove_one(&mut deduplicated, |d| {
|
remove_one(&mut deduplicated, |d| {
|
||||||
matches!(d, &(PropertyDeclaration::${property.camel_case}(..), _))
|
matches!(d, &(PropertyDeclaration::${property.camel_case}(..), _))
|
||||||
});
|
});
|
||||||
block.normal_count -= 1;
|
|
||||||
}
|
}
|
||||||
seen_important.set_${property.ident}()
|
seen_important.set_${property.ident}()
|
||||||
} else {
|
} else {
|
||||||
if seen_normal.get_${property.ident}() ||
|
if seen_normal.get_${property.ident}() ||
|
||||||
seen_important.get_${property.ident}() {
|
seen_important.get_${property.ident}() {
|
||||||
block.normal_count -= 1;
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
seen_normal.set_${property.ident}()
|
seen_normal.set_${property.ident}()
|
||||||
|
@ -631,13 +622,11 @@ fn deduplicate_property_declarations(block: &mut PropertyDeclarationBlock) {
|
||||||
remove_one(&mut deduplicated, |d| {
|
remove_one(&mut deduplicated, |d| {
|
||||||
matches!(d, &(PropertyDeclaration::Custom(ref n, _), _) if n == name)
|
matches!(d, &(PropertyDeclaration::Custom(ref n, _), _) if n == name)
|
||||||
});
|
});
|
||||||
block.normal_count -= 1;
|
|
||||||
}
|
}
|
||||||
seen_custom_important.push(name.clone())
|
seen_custom_important.push(name.clone())
|
||||||
} else {
|
} else {
|
||||||
if seen_custom_normal.contains(name) ||
|
if seen_custom_normal.contains(name) ||
|
||||||
seen_custom_important.contains(name) {
|
seen_custom_important.contains(name) {
|
||||||
block.normal_count -= 1;
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
seen_custom_normal.push(name.clone())
|
seen_custom_normal.push(name.clone())
|
||||||
|
|
|
@ -162,8 +162,8 @@ impl Stylist {
|
||||||
// Take apart the StyleRule into individual Rules and insert
|
// Take apart the StyleRule into individual Rules and insert
|
||||||
// them into the SelectorMap of that priority.
|
// them into the SelectorMap of that priority.
|
||||||
macro_rules! append(
|
macro_rules! append(
|
||||||
($style_rule: ident, $priority: ident, $importance: expr, $count: ident) => {
|
($style_rule: ident, $priority: ident, $importance: expr, $count: expr) => {
|
||||||
if $style_rule.declarations.$count > 0 {
|
if $count > 0 {
|
||||||
for selector in &$style_rule.selectors {
|
for selector in &$style_rule.selectors {
|
||||||
let map = if let Some(ref pseudo) = selector.pseudo_element {
|
let map = if let Some(ref pseudo) = selector.pseudo_element {
|
||||||
self.pseudos_map
|
self.pseudos_map
|
||||||
|
@ -191,6 +191,8 @@ impl Stylist {
|
||||||
for rule in stylesheet.effective_rules(&self.device) {
|
for rule in stylesheet.effective_rules(&self.device) {
|
||||||
match *rule {
|
match *rule {
|
||||||
CSSRule::Style(ref style_rule) => {
|
CSSRule::Style(ref style_rule) => {
|
||||||
|
let important_count = style_rule.declarations.important_count;
|
||||||
|
let normal_count = style_rule.declarations.declarations.len() as u32 - important_count;
|
||||||
append!(style_rule, normal, Importance::Normal, normal_count);
|
append!(style_rule, normal, Importance::Normal, normal_count);
|
||||||
append!(style_rule, important, Importance::Important, important_count);
|
append!(style_rule, important, Importance::Important, important_count);
|
||||||
rules_source_order += 1;
|
rules_source_order += 1;
|
||||||
|
@ -394,7 +396,7 @@ impl Stylist {
|
||||||
|
|
||||||
// Step 4: Normal style attributes.
|
// Step 4: Normal style attributes.
|
||||||
if let Some(ref sa) = style_attribute {
|
if let Some(ref sa) = style_attribute {
|
||||||
if sa.normal_count > 0 {
|
if sa.declarations.len() as u32 - sa.important_count > 0 {
|
||||||
relations |= AFFECTED_BY_STYLE_ATTRIBUTE;
|
relations |= AFFECTED_BY_STYLE_ATTRIBUTE;
|
||||||
Push::push(
|
Push::push(
|
||||||
applicable_declarations,
|
applicable_declarations,
|
||||||
|
|
|
@ -47,8 +47,6 @@ fn property_declaration_block_should_serialize_correctly() {
|
||||||
let block = PropertyDeclarationBlock {
|
let block = PropertyDeclarationBlock {
|
||||||
declarations: Arc::new(declarations),
|
declarations: Arc::new(declarations),
|
||||||
|
|
||||||
// Incorrect, but not used here:
|
|
||||||
normal_count: 0,
|
|
||||||
important_count: 0,
|
important_count: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -67,8 +65,6 @@ mod shorthand_serialization {
|
||||||
let block = PropertyDeclarationBlock {
|
let block = PropertyDeclarationBlock {
|
||||||
declarations: Arc::new(properties.into_iter().map(|d| (d, Importance::Normal)).collect()),
|
declarations: Arc::new(properties.into_iter().map(|d| (d, Importance::Normal)).collect()),
|
||||||
|
|
||||||
// Incorrect, but not used here:
|
|
||||||
normal_count: 0,
|
|
||||||
important_count: 0,
|
important_count: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -105,7 +105,6 @@ fn test_parse_stylesheet() {
|
||||||
(PropertyDeclaration::Custom(Atom::from("a"), DeclaredValue::Inherit),
|
(PropertyDeclaration::Custom(Atom::from("a"), DeclaredValue::Inherit),
|
||||||
Importance::Important),
|
Importance::Important),
|
||||||
]),
|
]),
|
||||||
normal_count: 0,
|
|
||||||
important_count: 2,
|
important_count: 2,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
@ -152,7 +151,6 @@ fn test_parse_stylesheet() {
|
||||||
longhands::display::SpecifiedValue::block)),
|
longhands::display::SpecifiedValue::block)),
|
||||||
Importance::Normal),
|
Importance::Normal),
|
||||||
]),
|
]),
|
||||||
normal_count: 1,
|
|
||||||
important_count: 0,
|
important_count: 0,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
@ -208,7 +206,6 @@ fn test_parse_stylesheet() {
|
||||||
(PropertyDeclaration::BackgroundClip(DeclaredValue::Initial),
|
(PropertyDeclaration::BackgroundClip(DeclaredValue::Initial),
|
||||||
Importance::Normal),
|
Importance::Normal),
|
||||||
]),
|
]),
|
||||||
normal_count: 8,
|
|
||||||
important_count: 0,
|
important_count: 0,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue