From 384fd59ad0047fc0130478585f2c22bf274ac5bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 8 Oct 2020 09:42:49 +0000 Subject: [PATCH] style: Use Option::as_deref() in style code. And drive-by simplify another function that was only doing Option::clone(). Differential Revision: https://phabricator.services.mozilla.com/D92839 --- components/style/gecko/selector_parser.rs | 2 +- components/style/matching.rs | 12 ++++++------ components/style/properties/properties.mako.rs | 2 +- components/style/traversal.rs | 10 ++-------- 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/components/style/gecko/selector_parser.rs b/components/style/gecko/selector_parser.rs index 3c25a43fe2e..6f8ac010e11 100644 --- a/components/style/gecko/selector_parser.rs +++ b/components/style/gecko/selector_parser.rs @@ -472,7 +472,7 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> { } fn default_namespace(&self) -> Option { - self.namespaces.default.as_ref().map(|ns| ns.clone()) + self.namespaces.default.clone() } fn namespace_for_prefix(&self, prefix: &Atom) -> Option { diff --git a/components/style/matching.rs b/components/style/matching.rs index c74d4feda3c..f81f9c3a233 100644 --- a/components/style/matching.rs +++ b/components/style/matching.rs @@ -395,7 +395,7 @@ trait PrivateMatchMethods: TElement { if context.shared.traversal_flags.for_animation_only() { self.handle_display_change_for_smil_if_needed( context, - old_values.as_ref().map(|v| &**v), + old_values.as_deref(), new_values, restyle_hint, ); @@ -408,7 +408,7 @@ trait PrivateMatchMethods: TElement { let mut tasks = UpdateAnimationsTasks::empty(); if self.needs_animations_update( context, - old_values.as_ref().map(|s| &**s), + old_values.as_deref(), new_values, /* pseudo_element = */ None, ) { @@ -417,7 +417,7 @@ trait PrivateMatchMethods: TElement { let before_change_style = if self.might_need_transitions_update( context, - old_values.as_ref().map(|s| &**s), + old_values.as_deref(), new_values, /* pseudo_element = */ None, ) { @@ -460,7 +460,7 @@ trait PrivateMatchMethods: TElement { if important_rules_changed { tasks.insert(UpdateAnimationsTasks::CASCADE_RESULTS); } - if new_values.is_display_property_changed_from_none(old_values.as_ref().map(|s| &**s)) { + if new_values.is_display_property_changed_from_none(old_values.as_deref()) { tasks.insert(UpdateAnimationsTasks::DISPLAY_CHANGED_FROM_NONE); } } @@ -638,14 +638,14 @@ trait PrivateMatchMethods: TElement { // map because this call will do a RwLock::read(). let needs_animations_update = self.needs_animations_update( context, - old_values.as_ref().map(|s| &**s), + old_values.as_deref(), new_values, pseudo_element, ); let might_need_transitions_update = self.might_need_transitions_update( context, - old_values.as_ref().map(|s| &**s), + old_values.as_deref(), new_values, pseudo_element, ); diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 1278ce9c5bb..24d396cdf0f 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -2966,7 +2966,7 @@ impl ComputedValues { /// Returns the visited style, if any. pub fn visited_style(&self) -> Option<<&ComputedValues> { - self.visited_style.as_ref().map(|s| &**s) + self.visited_style.as_deref() } /// Returns the visited rules, if applicable. diff --git a/components/style/traversal.rs b/components/style/traversal.rs index a60faaa446e..30d8ae29038 100644 --- a/components/style/traversal.rs +++ b/components/style/traversal.rs @@ -351,10 +351,7 @@ where rule_inclusion, PseudoElementResolution::IfApplicable, ) - .resolve_primary_style( - style.as_ref().map(|s| &**s), - layout_parent_style.as_ref().map(|s| &**s), - ); + .resolve_primary_style(style.as_deref(), layout_parent_style.as_deref()); let is_display_contents = primary_style.style().is_display_contents(); @@ -373,10 +370,7 @@ where rule_inclusion, PseudoElementResolution::Force, ) - .resolve_style( - style.as_ref().map(|s| &**s), - layout_parent_style.as_ref().map(|s| &**s), - ) + .resolve_style(style.as_deref(), layout_parent_style.as_deref()) .into() }