mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +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
|
@ -76,7 +76,7 @@ use matching::MatchMethods;
|
|||
use owning_ref::OwningHandle;
|
||||
use properties::ComputedValues;
|
||||
use selectors::matching::{ElementSelectorFlags, VisitedHandlingMode};
|
||||
use servo_arc::Arc;
|
||||
use servo_arc::{Arc, NonZeroPtrMut};
|
||||
use smallbitvec::SmallBitVec;
|
||||
use smallvec::SmallVec;
|
||||
use std::marker::PhantomData;
|
||||
|
@ -108,6 +108,16 @@ pub enum StyleSharingBehavior {
|
|||
Disallow,
|
||||
}
|
||||
|
||||
/// Opaque pointer type to compare ComputedValues identities.
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct OpaqueComputedValues(NonZeroPtrMut<()>);
|
||||
impl OpaqueComputedValues {
|
||||
fn from(cv: &ComputedValues) -> Self {
|
||||
let p = NonZeroPtrMut::new(cv as *const ComputedValues as *const () as *mut ());
|
||||
OpaqueComputedValues(p)
|
||||
}
|
||||
}
|
||||
|
||||
/// Some data we want to avoid recomputing all the time while trying to share
|
||||
/// style.
|
||||
#[derive(Debug, Default)]
|
||||
|
@ -121,6 +131,9 @@ pub struct ValidationData {
|
|||
/// The list of presentational attributes of the element.
|
||||
pres_hints: Option<SmallVec<[ApplicableDeclarationBlock; 5]>>,
|
||||
|
||||
/// The pointer identity of the parent ComputedValues.
|
||||
parent_style_identity: Option<OpaqueComputedValues>,
|
||||
|
||||
/// The cached result of matching this entry against the revalidation
|
||||
/// selectors.
|
||||
revalidation_match_results: Option<SmallBitVec>,
|
||||
|
@ -167,6 +180,18 @@ impl ValidationData {
|
|||
&*self.class_list.as_ref().unwrap()
|
||||
}
|
||||
|
||||
/// Get or compute the parent style identity.
|
||||
pub fn parent_style_identity<E>(&mut self, el: E) -> OpaqueComputedValues
|
||||
where E: TElement,
|
||||
{
|
||||
if self.parent_style_identity.is_none() {
|
||||
let parent = el.inheritance_parent().unwrap();
|
||||
self.parent_style_identity =
|
||||
Some(OpaqueComputedValues::from(parent.borrow_data().unwrap().styles.primary()));
|
||||
}
|
||||
self.parent_style_identity.as_ref().unwrap().clone()
|
||||
}
|
||||
|
||||
/// Computes the revalidation results if needed, and returns it.
|
||||
/// Inline so we know at compile time what bloom_known_valid is.
|
||||
#[inline]
|
||||
|
@ -250,6 +275,11 @@ impl<E: TElement> StyleSharingCandidate<E> {
|
|||
self.validation_data.pres_hints(self.element)
|
||||
}
|
||||
|
||||
/// Get the parent style identity.
|
||||
fn parent_style_identity(&mut self) -> OpaqueComputedValues {
|
||||
self.validation_data.parent_style_identity(self.element)
|
||||
}
|
||||
|
||||
/// Compute the bit vector of revalidation selector match results
|
||||
/// for this candidate.
|
||||
fn revalidation_match_results(
|
||||
|
@ -304,6 +334,11 @@ impl<E: TElement> StyleSharingTarget<E> {
|
|||
self.validation_data.pres_hints(self.element)
|
||||
}
|
||||
|
||||
/// Get the parent style identity.
|
||||
fn parent_style_identity(&mut self) -> OpaqueComputedValues {
|
||||
self.validation_data.parent_style_identity(self.element)
|
||||
}
|
||||
|
||||
fn revalidation_match_results(
|
||||
&mut self,
|
||||
stylist: &Stylist,
|
||||
|
@ -615,10 +650,7 @@ impl<E: TElement> StyleSharingCache<E> {
|
|||
// share styles and permit sharing across their children. The latter
|
||||
// check allows us to share style between cousins if the parents
|
||||
// shared style.
|
||||
let parent = target.inheritance_parent();
|
||||
let candidate_parent = candidate.element.inheritance_parent();
|
||||
if parent != candidate_parent &&
|
||||
!checks::can_share_style_across_parents(parent, candidate_parent) {
|
||||
if !checks::parents_allow_sharing(target, candidate) {
|
||||
trace!("Miss: Parent");
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue