style: Remove "reconstructed ancestor" checks.

This is only useful to avoid restyling NAC subtrees, but _not_ for ::before or
::after, in most cases. These subrees are small, and reframing is also not too
common, so I don't think it warrants the complexity.
This commit is contained in:
Emilio Cobos Álvarez 2017-11-09 15:37:54 +01:00
parent 333c6ef7fa
commit 49fe3d1c9f
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
2 changed files with 11 additions and 88 deletions

View file

@ -38,15 +38,16 @@ bitflags! {
/// traversed, so each traversal simply updates it with the appropriate
/// value.
const TRAVERSED_WITHOUT_STYLING = 1 << 1;
/// Whether we reframed/reconstructed any ancestor or self.
const ANCESTOR_WAS_RECONSTRUCTED = 1 << 2;
/// Whether the primary style of this element data was reused from another
/// element via a rule node comparison. This allows us to differentiate
/// between elements that shared styles because they met all the criteria
/// of the style sharing cache, compared to elements that reused style
/// structs via rule node identity. The former gives us stronger transitive
/// guarantees that allows us to apply the style sharing cache to cousins.
const PRIMARY_STYLE_REUSED_VIA_RULE_NODE = 1 << 3;
/// Whether the primary style of this element data was reused from
/// another element via a rule node comparison. This allows us to
/// differentiate between elements that shared styles because they met
/// all the criteria of the style sharing cache, compared to elements
/// that reused style structs via rule node identity.
///
/// The former gives us stronger transitive guarantees that allows us to
/// apply the style sharing cache to cousins.
const PRIMARY_STYLE_REUSED_VIA_RULE_NODE = 1 << 2;
}
}
@ -405,13 +406,7 @@ impl ElementData {
#[inline]
pub fn clear_restyle_flags_and_damage(&mut self) {
self.damage = RestyleDamage::empty();
self.flags.remove(ElementDataFlags::WAS_RESTYLED | ElementDataFlags::ANCESTOR_WAS_RECONSTRUCTED)
}
/// Returns whether this element or any ancestor is going to be
/// reconstructed.
pub fn reconstructed_self_or_ancestor(&self) -> bool {
self.reconstructed_ancestor() || self.reconstructed_self()
self.flags.remove(ElementDataFlags::WAS_RESTYLED);
}
/// Returns whether this element is going to be reconstructed.
@ -419,23 +414,6 @@ impl ElementData {
self.damage.contains(RestyleDamage::reconstruct())
}
/// Returns whether any ancestor of this element is going to be
/// reconstructed.
fn reconstructed_ancestor(&self) -> bool {
self.flags.contains(ElementDataFlags::ANCESTOR_WAS_RECONSTRUCTED)
}
/// Sets the flag that tells us whether we've reconstructed an ancestor.
pub fn set_reconstructed_ancestor(&mut self, reconstructed: bool) {
if reconstructed {
// If it weren't for animation-only traversals, we could assert
// `!self.reconstructed_ancestor()` here.
self.flags.insert(ElementDataFlags::ANCESTOR_WAS_RECONSTRUCTED);
} else {
self.flags.remove(ElementDataFlags::ANCESTOR_WAS_RECONSTRUCTED);
}
}
/// Mark this element as restyled, which is useful to know whether we need
/// to do a post-traversal.
pub fn set_restyled(&mut self) {

View file

@ -159,13 +159,6 @@ pub trait DomTraversal<E: TElement> : Sync {
let parent_data = parent.as_ref().and_then(|p| p.borrow_data());
if let Some(ref mut data) = data {
// Make sure we don't have any stale RECONSTRUCTED_ANCESTOR bits
// from the last traversal (at a potentially-higher root).
//
// From the perspective of this traversal, the root cannot have
// reconstructed ancestors.
data.set_reconstructed_ancestor(false);
if !traversal_flags.for_animation_only() {
// Invalidate our style, and that of our siblings and
// descendants as needed.
@ -247,48 +240,6 @@ pub trait DomTraversal<E: TElement> : Sync {
_ => return true,
};
// If the element is native-anonymous and an ancestor frame will be
// reconstructed, the child and all its descendants will be destroyed.
// In that case, we wouldn't need to traverse the subtree...
//
// Except if there could be transitions of pseudo-elements, in which
// case we still need to process them, unfortunately.
//
// We need to conservatively continue the traversal to style the
// pseudo-element in order to properly process potentially-new
// transitions that we won't see otherwise.
//
// But it may be that we no longer match, so detect that case and act
// appropriately here.
if el.is_native_anonymous() {
if let Some(parent_data) = parent_data {
let going_to_reframe =
parent_data.reconstructed_self_or_ancestor();
let mut is_before_or_after_pseudo = false;
if let Some(pseudo) = el.implemented_pseudo_element() {
if pseudo.is_before_or_after() {
is_before_or_after_pseudo = true;
let still_match =
parent_data.styles.pseudos.get(&pseudo).is_some();
if !still_match {
debug_assert!(going_to_reframe,
"We're removing a pseudo, so we \
should reframe!");
return false;
}
}
}
if going_to_reframe && !is_before_or_after_pseudo {
debug!("Element {:?} is in doomed NAC subtree, \
culling traversal", el);
return false;
}
}
}
// If the dirty descendants bit is set, we need to traverse no matter
// what. Skip examining the ElementData.
if el.has_dirty_descendants() {
@ -584,7 +535,6 @@ where
data,
propagated_hint,
child_cascade_requirement,
data.reconstructed_self_or_ancestor(),
note_child
);
}
@ -826,7 +776,6 @@ fn note_children<E, D, F>(
data: &ElementData,
propagated_hint: RestyleHint,
cascade_requirement: ChildCascadeRequirement,
reconstructed_ancestor: bool,
mut note_child: F,
)
where
@ -866,10 +815,6 @@ where
}
if let Some(ref mut child_data) = child_data {
// Propagate the parent restyle hint, that may make us restyle the whole
// subtree.
child_data.set_reconstructed_ancestor(reconstructed_ancestor);
let mut child_hint = propagated_hint;
match cascade_requirement {
ChildCascadeRequirement::CanSkipCascade => {}