Return the element rather than styles from the style sharing cache.

This gives us more flexibility, and doesn't cost us anything.

MozReview-Commit-ID: CuvOEcLA3My
This commit is contained in:
Bobby Holley 2017-09-12 16:42:04 -07:00
parent 729db5ccec
commit 9092e6b4c2
2 changed files with 7 additions and 7 deletions

View file

@ -70,7 +70,6 @@ use atomic_refcell::{AtomicRefCell, AtomicRefMut};
use bloom::StyleBloom;
use cache::LRUCache;
use context::{SelectorFlagsMap, SharedStyleContext, StyleContext};
use data::ElementStyles;
use dom::{TElement, SendElement};
use matching::MatchMethods;
use owning_ref::OwningHandle;
@ -377,7 +376,7 @@ impl<E: TElement> StyleSharingTarget<E> {
pub fn share_style_if_possible(
&mut self,
context: &mut StyleContext<E>,
) -> Option<ElementStyles> {
) -> Option<E> {
let cache = &mut context.thread_local.sharing_cache;
let shared_context = &context.shared;
let selector_flags_map = &mut context.thread_local.selector_flags;
@ -435,7 +434,7 @@ impl<E: TElement> SharingCache<E> {
});
}
fn lookup<F>(&mut self, mut is_match: F) -> Option<ElementStyles>
fn lookup<F>(&mut self, mut is_match: F) -> Option<E>
where
F: FnMut(&mut StyleSharingCandidate<E>) -> bool
{
@ -453,7 +452,7 @@ impl<E: TElement> SharingCache<E> {
self.entries.touch(i);
let front = self.entries.front_mut().unwrap();
debug_assert!(is_match(front));
Some(front.element.borrow_data().unwrap().styles.clone())
Some(front.element)
}
}
}
@ -610,7 +609,7 @@ impl<E: TElement> StyleSharingCache<E> {
selector_flags_map: &mut SelectorFlagsMap<E>,
bloom_filter: &StyleBloom<E>,
target: &mut StyleSharingTarget<E>,
) -> Option<ElementStyles> {
) -> Option<E> {
if shared_context.options.disable_style_sharing_cache {
debug!("{:?} Cannot share style: style sharing cache disabled",
target.element);

View file

@ -655,9 +655,10 @@ where
// Now that our bloom filter is set up, try the style sharing
// cache.
match target.share_style_if_possible(context) {
Some(styles) => {
Some(shareable_element) => {
context.thread_local.statistics.styles_shared += 1;
styles
let shareable_data = shareable_element.borrow_data().unwrap();
shareable_data.styles.clone()
}
None => {
context.thread_local.statistics.elements_matched += 1;