diff options
Diffstat (limited to 'components')
-rw-r--r-- | components/style/sharing/mod.rs | 51 | ||||
-rw-r--r-- | components/style/stylist.rs | 7 |
2 files changed, 27 insertions, 31 deletions
diff --git a/components/style/sharing/mod.rs b/components/style/sharing/mod.rs index fd25c1b72cc..729a8592187 100644 --- a/components/style/sharing/mod.rs +++ b/components/style/sharing/mod.rs @@ -152,24 +152,25 @@ impl ValidationData { /// Get or compute the list of presentational attributes associated with /// this element. pub fn pres_hints<E>(&mut self, element: E) -> &[ApplicableDeclarationBlock] - where E: TElement, + where + E: TElement, { - if self.pres_hints.is_none() { + self.pres_hints.get_or_insert_with(|| { let mut pres_hints = SmallVec::new(); element.synthesize_presentational_hints_for_legacy_attributes( VisitedHandlingMode::AllLinksUnvisited, &mut pres_hints ); - self.pres_hints = Some(pres_hints); - } - &*self.pres_hints.as_ref().unwrap() + pres_hints + }) } /// Get or compute the class-list associated with this element. pub fn class_list<E>(&mut self, element: E) -> &[Atom] - where E: TElement, + where + E: TElement, { - if self.class_list.is_none() { + self.class_list.get_or_insert_with(|| { let mut class_list = SmallVec::<[Atom; 5]>::new(); element.each_class(|c| class_list.push(c.clone())); // Assuming there are a reasonable number of classes (we use the @@ -179,21 +180,20 @@ impl ValidationData { if !class_list.spilled() { class_list.sort_by(|a, b| a.get_hash().cmp(&b.get_hash())); } - self.class_list = Some(class_list); - } - &*self.class_list.as_ref().unwrap() + class_list + }) } /// Get or compute the parent style identity. pub fn parent_style_identity<E>(&mut self, el: E) -> OpaqueComputedValues - where E: TElement, + where + E: TElement, { - if self.parent_style_identity.is_none() { + self.parent_style_identity.get_or_insert_with(|| { let parent = el.inheritance_parent().unwrap(); - self.parent_style_identity = - Some(OpaqueComputedValues::from(parent.borrow_data().unwrap().styles.primary())); - } - self.parent_style_identity.as_ref().unwrap().clone() + let values = OpaqueComputedValues::from(parent.borrow_data().unwrap().styles.primary()); + values + }).clone() } /// Computes the revalidation results if needed, and returns it. @@ -212,7 +212,7 @@ impl ValidationData { E: TElement, F: FnMut(&E, ElementSelectorFlags), { - if self.revalidation_match_results.is_none() { + self.revalidation_match_results.get_or_insert_with(|| { // The bloom filter may already be set up for our element. // If it is, use it. If not, we must be in a candidate // (i.e. something in the cache), and the element is one @@ -230,16 +230,13 @@ impl ValidationData { None } }; - self.revalidation_match_results = - Some(stylist.match_revalidation_selectors( - element, - bloom_to_use, - nth_index_cache, - flags_setter, - )); - } - - self.revalidation_match_results.as_ref().unwrap() + stylist.match_revalidation_selectors( + element, + bloom_to_use, + nth_index_cache, + flags_setter, + ) + }) } } diff --git a/components/style/stylist.rs b/components/style/stylist.rs index e499f3cb646..60e41538af1 100644 --- a/components/style/stylist.rs +++ b/components/style/stylist.rs @@ -2271,10 +2271,9 @@ impl CascadeData { ); let style_rule_cascade_data = if selector.is_slotted() { - if self.slotted_rule_data.is_none() { - self.slotted_rule_data = Some(Box::new(StyleRuleCascadeData::new())); - } - self.slotted_rule_data.as_mut().unwrap() + self.slotted_rule_data.get_or_insert_with(|| { + Box::new(StyleRuleCascadeData::new()) + }) } else { &mut self.normal_rule_data }; |