servo: Merge #18497 - style: Don't cache styles that got a cache hit on the second pass (from emilio:no-cache-if-cached); r=heycam

This avoids doing wasted work, at least in the recascade case, and pretty likely
in the other as well.

Source-Repo: https://github.com/servo/servo
Source-Revision: 988728e9d5c66e6bf2f9e0e03a50a814d0e1f2ab

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 68555686bb062ce696e70ffcbdbd07fe6960a5da
This commit is contained in:
Emilio Cobos Álvarez 2017-09-14 05:23:09 -05:00
Родитель fb683c3ffc
Коммит a47c2d6ea7
2 изменённых файлов: 22 добавлений и 15 удалений

Просмотреть файл

@ -82,6 +82,7 @@ use smallvec::SmallVec;
use std::marker::PhantomData;
use std::mem;
use std::ops::Deref;
use style_resolver::PrimaryStyle;
use stylist::Stylist;
mod checks;
@ -546,11 +547,18 @@ impl<E: TElement> StyleSharingCache<E> {
///
/// NB: We pass a source for the validation data, rather than the data itself,
/// to avoid memmoving at each function call. See rust issue #42763.
pub fn insert_if_possible(&mut self,
element: &E,
style: &ComputedValues,
validation_data_holder: Option<&mut StyleSharingTarget<E>>,
dom_depth: usize) {
pub fn insert_if_possible(
&mut self,
element: &E,
style: &PrimaryStyle,
validation_data_holder: Option<&mut StyleSharingTarget<E>>,
dom_depth: usize,
) {
if style.0.reused_via_rule_node {
debug!("Failing to insert into the cached: this was a cached style");
return;
}
let parent = match element.traversal_parent() {
Some(element) => element,
None => {
@ -583,7 +591,7 @@ impl<E: TElement> StyleSharingCache<E> {
//
// These are things we don't check in the candidate match because they
// are either uncommon or expensive.
let box_style = style.get_box();
let box_style = style.style().get_box();
if box_style.specifies_transitions() {
debug!("Failing to insert to the cache: transitions");
return;

Просмотреть файл

@ -678,14 +678,12 @@ where
resolver.resolve_style_with_default_parents()
};
context.thread_local
.sharing_cache
.insert_if_possible(
&element,
new_styles.primary.style(),
Some(&mut target),
traversal_data.current_dom_depth,
);
context.thread_local.sharing_cache.insert_if_possible(
&element,
&new_styles.primary,
Some(&mut target),
traversal_data.current_dom_depth,
);
new_styles
}
@ -724,9 +722,10 @@ where
resolver.cascade_styles_with_default_parents(cascade_inputs)
};
context.thread_local.sharing_cache.insert_if_possible(
&element,
new_styles.primary.style(),
&new_styles.primary,
None,
traversal_data.current_dom_depth,
);