mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
style: Use Option::get_or_insert_with.
Less unwraps is better.
This commit is contained in:
parent
bfc91c5e12
commit
3595c98411
2 changed files with 27 additions and 31 deletions
|
@ -152,24 +152,25 @@ impl ValidationData {
|
||||||
/// Get or compute the list of presentational attributes associated with
|
/// Get or compute the list of presentational attributes associated with
|
||||||
/// this element.
|
/// this element.
|
||||||
pub fn pres_hints<E>(&mut self, element: E) -> &[ApplicableDeclarationBlock]
|
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();
|
let mut pres_hints = SmallVec::new();
|
||||||
element.synthesize_presentational_hints_for_legacy_attributes(
|
element.synthesize_presentational_hints_for_legacy_attributes(
|
||||||
VisitedHandlingMode::AllLinksUnvisited,
|
VisitedHandlingMode::AllLinksUnvisited,
|
||||||
&mut pres_hints
|
&mut pres_hints
|
||||||
);
|
);
|
||||||
self.pres_hints = Some(pres_hints);
|
pres_hints
|
||||||
}
|
})
|
||||||
&*self.pres_hints.as_ref().unwrap()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get or compute the class-list associated with this element.
|
/// Get or compute the class-list associated with this element.
|
||||||
pub fn class_list<E>(&mut self, element: E) -> &[Atom]
|
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();
|
let mut class_list = SmallVec::<[Atom; 5]>::new();
|
||||||
element.each_class(|c| class_list.push(c.clone()));
|
element.each_class(|c| class_list.push(c.clone()));
|
||||||
// Assuming there are a reasonable number of classes (we use the
|
// Assuming there are a reasonable number of classes (we use the
|
||||||
|
@ -179,21 +180,20 @@ impl ValidationData {
|
||||||
if !class_list.spilled() {
|
if !class_list.spilled() {
|
||||||
class_list.sort_by(|a, b| a.get_hash().cmp(&b.get_hash()));
|
class_list.sort_by(|a, b| a.get_hash().cmp(&b.get_hash()));
|
||||||
}
|
}
|
||||||
self.class_list = Some(class_list);
|
class_list
|
||||||
}
|
})
|
||||||
&*self.class_list.as_ref().unwrap()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get or compute the parent style identity.
|
/// Get or compute the parent style identity.
|
||||||
pub fn parent_style_identity<E>(&mut self, el: E) -> OpaqueComputedValues
|
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();
|
let parent = el.inheritance_parent().unwrap();
|
||||||
self.parent_style_identity =
|
let values = OpaqueComputedValues::from(parent.borrow_data().unwrap().styles.primary());
|
||||||
Some(OpaqueComputedValues::from(parent.borrow_data().unwrap().styles.primary()));
|
values
|
||||||
}
|
}).clone()
|
||||||
self.parent_style_identity.as_ref().unwrap().clone()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Computes the revalidation results if needed, and returns it.
|
/// Computes the revalidation results if needed, and returns it.
|
||||||
|
@ -212,7 +212,7 @@ impl ValidationData {
|
||||||
E: TElement,
|
E: TElement,
|
||||||
F: FnMut(&E, ElementSelectorFlags),
|
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.
|
// The bloom filter may already be set up for our element.
|
||||||
// If it is, use it. If not, we must be in a candidate
|
// If it is, use it. If not, we must be in a candidate
|
||||||
// (i.e. something in the cache), and the element is one
|
// (i.e. something in the cache), and the element is one
|
||||||
|
@ -230,16 +230,13 @@ impl ValidationData {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
self.revalidation_match_results =
|
stylist.match_revalidation_selectors(
|
||||||
Some(stylist.match_revalidation_selectors(
|
|
||||||
element,
|
element,
|
||||||
bloom_to_use,
|
bloom_to_use,
|
||||||
nth_index_cache,
|
nth_index_cache,
|
||||||
flags_setter,
|
flags_setter,
|
||||||
));
|
)
|
||||||
}
|
})
|
||||||
|
|
||||||
self.revalidation_match_results.as_ref().unwrap()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2271,10 +2271,9 @@ impl CascadeData {
|
||||||
);
|
);
|
||||||
|
|
||||||
let style_rule_cascade_data = if selector.is_slotted() {
|
let style_rule_cascade_data = if selector.is_slotted() {
|
||||||
if self.slotted_rule_data.is_none() {
|
self.slotted_rule_data.get_or_insert_with(|| {
|
||||||
self.slotted_rule_data = Some(Box::new(StyleRuleCascadeData::new()));
|
Box::new(StyleRuleCascadeData::new())
|
||||||
}
|
})
|
||||||
self.slotted_rule_data.as_mut().unwrap()
|
|
||||||
} else {
|
} else {
|
||||||
&mut self.normal_rule_data
|
&mut self.normal_rule_data
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue