style: Don't cache structs if they have been adjusted.

StyleAdjuster looks a bunch of things that we don't record as dependencies.
This commit is contained in:
Cameron McCormack 2017-09-13 16:08:30 +08:00
parent 73ae5ffd94
commit a7dd19cfb1

View file

@ -2602,6 +2602,11 @@ pub struct StyleBuilder<'a> {
/// The pseudo-element this style will represent.
pseudo: Option<<&'a PseudoElement>,
/// Whether we have mutated any reset structs since the the last time
/// `clear_modified_reset` was called. This is used to tell whether the
/// `StyleAdjuster` did any work.
modified_reset: bool,
/// The writing mode flags.
///
/// TODO(emilio): Make private.
@ -2665,6 +2670,7 @@ impl<'a> StyleBuilder<'a> {
reset_style,
pseudo,
rules,
modified_reset: false,
custom_properties,
writing_mode,
font_size_keyword,
@ -2706,6 +2712,7 @@ impl<'a> StyleBuilder<'a> {
inherited_style_ignoring_first_line: inherited_style,
reset_style,
pseudo,
modified_reset: false,
rules: None, // FIXME(emilio): Dubious...
custom_properties: style_to_derive_from.custom_properties(),
writing_mode: style_to_derive_from.writing_mode,
@ -2745,6 +2752,7 @@ impl<'a> StyleBuilder<'a> {
% if not property.style_struct.inherited:
self.flags.insert(::properties::computed_value_flags::INHERITS_RESET_STYLE);
self.modified_reset = true;
% endif
% if property.ident == "content":
@ -2770,6 +2778,10 @@ impl<'a> StyleBuilder<'a> {
let reset_struct =
self.reset_style.get_${property.style_struct.name_lower}();
% if not property.style_struct.inherited:
self.modified_reset = true;
% endif
self.${property.style_struct.ident}.mutate()
.reset_${property.ident}(
reset_struct,
@ -2786,6 +2798,10 @@ impl<'a> StyleBuilder<'a> {
&mut self,
value: longhands::${property.ident}::computed_value::T
) {
% if not property.style_struct.inherited:
self.modified_reset = true;
% endif
<% props_need_device = ["content", "list_style_type", "font_variant_alternates"] %>
self.${property.style_struct.ident}.mutate()
.set_${property.ident}(
@ -2849,11 +2865,17 @@ impl<'a> StyleBuilder<'a> {
/// Gets a mutable view of the current `${style_struct.name}` style.
pub fn mutate_${style_struct.name_lower}(&mut self) -> &mut style_structs::${style_struct.name} {
% if not property.style_struct.inherited:
self.modified_reset = true;
% endif
self.${style_struct.ident}.mutate()
}
/// Gets a mutable view of the current `${style_struct.name}` style.
pub fn take_${style_struct.name_lower}(&mut self) -> UniqueArc<style_structs::${style_struct.name}> {
% if not property.style_struct.inherited:
self.modified_reset = true;
% endif
self.${style_struct.ident}.take()
}
@ -2902,6 +2924,16 @@ impl<'a> StyleBuilder<'a> {
longhands::_moz_top_layer::computed_value::T::top)
}
/// Clears the "have any reset structs been modified" flag.
fn clear_modified_reset(&mut self) {
self.modified_reset = false;
}
/// Returns whether we have mutated any reset structs since the the last
/// time `clear_modified_reset` was called.
fn modified_reset(&self) -> bool {
self.modified_reset
}
/// Turns this `StyleBuilder` into a proper `ComputedValues` instance.
pub fn build(self) -> Arc<ComputedValues> {
@ -3469,11 +3501,6 @@ where
let mut builder = context.builder;
{
StyleAdjuster::new(&mut builder)
.adjust(layout_parent_style, flags);
}
% if product == "gecko":
if let Some(ref mut bg) = builder.get_background_if_mutated() {
bg.fill_arrays();
@ -3493,6 +3520,16 @@ where
}
% endif
builder.clear_modified_reset();
StyleAdjuster::new(&mut builder)
.adjust(layout_parent_style, flags);
if builder.modified_reset() {
context.rule_cache_conditions.borrow_mut()
.set_uncacheable();
}
builder.build()
}