From 9321265b38a9c69222d5a45d217e8b299ad6585a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 12 Jun 2023 19:42:23 +0000 Subject: [PATCH] style: Clean up Context::for_non_inherited_property We don't ever check the particular property, so it can just be a boolean. Differential Revision: https://phabricator.services.mozilla.com/D180680 --- components/style/properties/cascade.rs | 2 +- components/style/properties/helpers.mako.rs | 8 +------ .../helpers/animated_properties.mako.rs | 6 +----- components/style/values/computed/mod.rs | 21 +++++++++---------- components/style/values/specified/length.rs | 14 ++++++------- 5 files changed, 19 insertions(+), 32 deletions(-) diff --git a/components/style/properties/cascade.rs b/components/style/properties/cascade.rs index 4cd0a2c273d..f9951e2cfc5 100644 --- a/components/style/properties/cascade.rs +++ b/components/style/properties/cascade.rs @@ -1018,7 +1018,7 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> { let new_size = match info.kw { specified::FontSizeKeyword::None => return, _ => { - self.context.for_non_inherited_property = None; + self.context.for_non_inherited_property = false; specified::FontSize::Keyword(info).to_computed_value(self.context) }, }; diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs index e160e71d17e..5e1eea5072f 100644 --- a/components/style/properties/helpers.mako.rs +++ b/components/style/properties/helpers.mako.rs @@ -431,13 +431,7 @@ declaration: &PropertyDeclaration, context: &mut computed::Context, ) { - context.for_non_inherited_property = - % if property.style_struct.inherited: - None; - % else: - Some(LonghandId::${property.camel_case}); - % endif - + context.for_non_inherited_property = ${"false" if property.style_struct.inherited else "true"}; let specified_value = match *declaration { PropertyDeclaration::${property.camel_case}(ref value) => value, PropertyDeclaration::CSSWideKeyword(ref declaration) => { diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index 00ccbb2c62d..d1e28a5f97b 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -270,11 +270,7 @@ impl AnimationValue { let longhand_id = unsafe { *(&decl_repr.tag as *const u16 as *const LonghandId) }; - % if inherit: - context.for_non_inherited_property = None; - % else: - context.for_non_inherited_property = Some(longhand_id); - % endif + context.for_non_inherited_property = ${"false" if inherit else "true"}; % if system: if let Some(sf) = value.get_system() { longhands::system_font::resolve_system_font(sf, context) diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index 207e796a102..8f9af36c478 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -20,7 +20,7 @@ use crate::font_metrics::{FontMetrics, FontMetricsOrientation}; use crate::media_queries::Device; #[cfg(feature = "gecko")] use crate::properties; -use crate::properties::{ComputedValues, LonghandId, StyleBuilder}; +use crate::properties::{ComputedValues, StyleBuilder}; use crate::rule_cache::RuleCacheConditions; use crate::stylesheets::container_rule::{ ContainerInfo, ContainerSizeQuery, ContainerSizeQueryResult, @@ -185,11 +185,10 @@ pub struct Context<'a> { /// Returns the container information to evaluate a given container query. pub container_info: Option, - /// The property we are computing a value for, if it is a non-inherited - /// property. None if we are computed a value for an inherited property - /// or not computing for a property at all (e.g. in a media query - /// evaluation). - pub for_non_inherited_property: Option, + /// Whether we're computing a value for a non-inherited property. + /// False if we are computed a value for an inherited property or not computing for a property + /// at all (e.g. in a media query evaluation). + pub for_non_inherited_property: bool, /// The conditions to cache a rule node on the rule cache. /// @@ -223,7 +222,7 @@ impl<'a> Context<'a> { quirks_mode, for_smil_animation: false, container_info: None, - for_non_inherited_property: None, + for_non_inherited_property: false, rule_cache_conditions: RefCell::new(&mut conditions), container_size_query: RefCell::new(ContainerSizeQuery::none()), }; @@ -258,7 +257,7 @@ impl<'a> Context<'a> { quirks_mode, for_smil_animation: false, container_info, - for_non_inherited_property: None, + for_non_inherited_property: false, rule_cache_conditions: RefCell::new(&mut conditions), container_size_query: RefCell::new(container_size_query), }; @@ -281,7 +280,7 @@ impl<'a> Context<'a> { quirks_mode, container_info: None, for_smil_animation: false, - for_non_inherited_property: None, + for_non_inherited_property: false, rule_cache_conditions: RefCell::new(rule_cache_conditions), container_size_query: RefCell::new(container_size_query), } @@ -303,7 +302,7 @@ impl<'a> Context<'a> { quirks_mode, container_info: None, for_smil_animation, - for_non_inherited_property: None, + for_non_inherited_property: false, rule_cache_conditions: RefCell::new(rule_cache_conditions), container_size_query: RefCell::new(container_size_query), } @@ -321,7 +320,7 @@ impl<'a> Context<'a> { orientation: FontMetricsOrientation, retrieve_math_scales: bool, ) -> FontMetrics { - if self.for_non_inherited_property.is_some() { + if self.for_non_inherited_property { self.rule_cache_conditions.borrow_mut().set_uncacheable(); } self.builder.add_flags(match base_size { diff --git a/components/style/values/specified/length.rs b/components/style/values/specified/length.rs index 06001b294ef..45a3154fc0d 100644 --- a/components/style/values/specified/length.rs +++ b/components/style/values/specified/length.rs @@ -180,13 +180,11 @@ impl FontRelativeLength { let reference_font_size = base_size.resolve(context); match *self { Self::Em(length) => { - if context.for_non_inherited_property.is_some() { - if base_size == FontBaseSize::CurrentStyle { - context - .rule_cache_conditions - .borrow_mut() - .set_font_size_dependency(reference_font_size.computed_size); - } + if context.for_non_inherited_property && base_size == FontBaseSize::CurrentStyle { + context + .rule_cache_conditions + .borrow_mut() + .set_font_size_dependency(reference_font_size.computed_size); } (reference_font_size.computed_size(), length) @@ -786,7 +784,7 @@ impl ContainerRelativeLength { /// Computes the given container-relative length. pub fn to_computed_value(&self, context: &Context) -> CSSPixelLength { - if context.for_non_inherited_property.is_some() { + if context.for_non_inherited_property { context.rule_cache_conditions.borrow_mut().set_uncacheable(); } let size = context.get_container_size_query();