mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Cache the parent CV identity on ValidationData.
This will make the linear probing faster. If we end up implementing the two-tier cache setup, this code will be unnecessary and can go away. MozReview-Commit-ID: BRfV5ump34n
This commit is contained in:
parent
7b019f807b
commit
729db5ccec
2 changed files with 60 additions and 24 deletions
|
@ -10,26 +10,30 @@ use Atom;
|
|||
use bloom::StyleBloom;
|
||||
use context::{SelectorFlagsMap, SharedStyleContext};
|
||||
use dom::TElement;
|
||||
use servo_arc::Arc;
|
||||
use sharing::{StyleSharingCandidate, StyleSharingTarget};
|
||||
|
||||
/// Whether styles may be shared across the children of the given parent elements.
|
||||
/// This is used to share style across cousins.
|
||||
///
|
||||
/// Both elements need to be styled already.
|
||||
pub fn can_share_style_across_parents<E>(first: Option<E>, second: Option<E>) -> bool
|
||||
/// Determines whether a target and a candidate have compatible parents for sharing.
|
||||
pub fn parents_allow_sharing<E>(
|
||||
target: &mut StyleSharingTarget<E>,
|
||||
candidate: &mut StyleSharingCandidate<E>
|
||||
) -> bool
|
||||
where E: TElement,
|
||||
{
|
||||
let (first, second) = match (first, second) {
|
||||
(Some(f), Some(s)) => (f, s),
|
||||
_ => return false,
|
||||
};
|
||||
// If the identity of the parent style isn't equal, we can't share. We check
|
||||
// this first, because the result is cached.
|
||||
if target.parent_style_identity() != candidate.parent_style_identity() {
|
||||
return false;
|
||||
}
|
||||
|
||||
debug_assert_ne!(first, second);
|
||||
|
||||
let first_data = first.borrow_data().unwrap();
|
||||
let second_data = second.borrow_data().unwrap();
|
||||
// Siblings can always share.
|
||||
let parent = target.inheritance_parent().unwrap();
|
||||
let candidate_parent = candidate.element.inheritance_parent().unwrap();
|
||||
if parent == candidate_parent {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Cousins are a bit more complicated.
|
||||
//
|
||||
// If a parent element was already styled and we traversed past it without
|
||||
// restyling it, that may be because our clever invalidation logic was able
|
||||
// to prove that the styles of that element would remain unchanged despite
|
||||
|
@ -40,14 +44,14 @@ pub fn can_share_style_across_parents<E>(first: Option<E>, second: Option<E>) ->
|
|||
//
|
||||
// This is a somewhat conservative check. We could tighten it by having the
|
||||
// invalidation logic explicitly flag elements for which it ellided styling.
|
||||
if first_data.traversed_without_styling() || second_data.traversed_without_styling() {
|
||||
let parent_data = parent.borrow_data().unwrap();
|
||||
let candidate_parent_data = candidate_parent.borrow_data().unwrap();
|
||||
if parent_data.traversed_without_styling() ||
|
||||
candidate_parent_data.traversed_without_styling() {
|
||||
return false;
|
||||
}
|
||||
|
||||
let same_computed_values =
|
||||
Arc::ptr_eq(first_data.styles.primary(), second_data.styles.primary());
|
||||
|
||||
same_computed_values
|
||||
true
|
||||
}
|
||||
|
||||
/// Whether two elements have the same same style attribute (by pointer identity).
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue