Skip rule node which contains only inherited properties for rule cache.

This commit is contained in:
Xidorn Quan 2018-01-05 09:54:59 +11:00
parent 782e3fe4e4
commit 3593392788
6 changed files with 75 additions and 7 deletions

View file

@ -283,6 +283,12 @@ impl PropertyDeclarationBlock {
self.longhands.contains(id)
}
/// Returns whether this block contains any reset longhand.
#[inline]
pub fn contains_any_reset(&self) -> bool {
self.longhands.contains_any_reset()
}
/// Get a declaration for a given property.
///
/// NOTE: This is linear time.

View file

@ -309,6 +309,16 @@ impl LonghandIdSet {
true
}
/// Returns whether this set contains any longhand that `other` also contains.
pub fn contains_any(&self, other: &Self) -> bool {
for (self_cell, other_cell) in self.storage.iter().zip(other.storage.iter()) {
if (*self_cell & *other_cell) != 0 {
return true;
}
}
false
}
/// Create an empty set
#[inline]
pub fn new() -> LonghandIdSet {
@ -322,6 +332,13 @@ impl LonghandIdSet {
(self.storage[bit / 32] & (1 << (bit % 32))) != 0
}
/// Return whether this set contains any reset longhand.
#[inline]
pub fn contains_any_reset(&self) -> bool {
${static_longhand_id_set("RESET", lambda p: not p.style_struct.inherited)}
self.contains_any(&RESET)
}
/// Add the given property to the set
#[inline]
pub fn insert(&mut self, id: LonghandId) {
@ -3165,6 +3182,7 @@ pub fn cascade(
device,
pseudo,
rule_node,
guards,
iter_declarations,
parent_style,
parent_style_ignoring_first_line,
@ -3184,6 +3202,7 @@ pub fn apply_declarations<'a, F, I>(
device: &Device,
pseudo: Option<<&PseudoElement>,
rules: &StrongRuleNode,
guards: &StylesheetGuards,
iter_declarations: F,
parent_style: Option<<&ComputedValues>,
parent_style_ignoring_first_line: Option<<&ComputedValues>,
@ -3486,7 +3505,7 @@ where
% endif
}
if let Some(style) = rule_cache.and_then(|c| c.find(&context.builder)) {
if let Some(style) = rule_cache.and_then(|c| c.find(guards, &context.builder)) {
context.builder.copy_reset_from(style);
apply_reset = false;
}