Skip to content

Commit

Permalink
Style sharing cache for visited
Browse files Browse the repository at this point in the history
The style sharing cache stores the regular `ComputedValues`, so it would also
have the visited values as well for anything inserted into the cache (since they
are nested inside).  Unlike all other element states, a change in state of
unvisited vs. visited does not change the style system's output, since we have
already computed both possible outputs up front.

We change the element state checks when looking for style sharing cache hits to
ignore visitedness, since that's handled by the two separate sets of values.

MozReview-Commit-ID: Dt8uK8gSQSP
  • Loading branch information
jryans committed May 24, 2017
1 parent 582ce1f commit 47c8574
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions components/style/sharing/checks.rs
Expand Up @@ -8,6 +8,7 @@

use context::{CurrentElementInfo, SelectorFlagsMap, SharedStyleContext};
use dom::TElement;
use element_state::*;
use matching::MatchMethods;
use selectors::bloom::BloomFilter;
use selectors::matching::{ElementSelectorFlags, StyleRelations};
Expand Down Expand Up @@ -80,6 +81,20 @@ pub fn have_same_class<E>(element: E,
element_class_attributes == *candidate.class_attributes.as_ref().unwrap()
}

/// Compare element and candidate state, but ignore visitedness. Styles don't
/// actually changed based on visitedness (since both possibilities are computed
/// up front), so it's safe to share styles if visitedness differs.
pub fn have_same_state_ignoring_visitedness<E>(element: E,
candidate: &StyleSharingCandidate<E>)
-> bool
where E: TElement,
{
let state_mask = !IN_VISITED_OR_UNVISITED_STATE;
let state = element.get_state() & state_mask;
let candidate_state = candidate.element.get_state() & state_mask;
state == candidate_state
}

/// Whether a given element and a candidate match the same set of "revalidation"
/// selectors.
///
Expand Down
2 changes: 1 addition & 1 deletion components/style/sharing/mod.rs
Expand Up @@ -349,7 +349,7 @@ impl<E: TElement> StyleSharingCandidateCache<E> {
miss!(UserAndAuthorRules)
}

if element.get_state() != candidate.element.get_state() {
if !checks::have_same_state_ignoring_visitedness(element, candidate) {
miss!(State)
}

Expand Down

0 comments on commit 47c8574

Please sign in to comment.