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

View file

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