mirror of
https://github.com/servo/servo.git
synced 2025-06-08 08:33:26 +00:00
style: Use the ? operator for Option
This commit is contained in:
parent
c52d347022
commit
3005a26daf
13 changed files with 47 additions and 129 deletions
|
@ -1750,22 +1750,17 @@ impl Fragment {
|
||||||
|
|
||||||
let character_breaking_strategy =
|
let character_breaking_strategy =
|
||||||
text_fragment_info.run.character_slices_in_range(&text_fragment_info.range);
|
text_fragment_info.run.character_slices_in_range(&text_fragment_info.range);
|
||||||
match self.calculate_split_position_using_breaking_strategy(character_breaking_strategy,
|
|
||||||
max_inline_size,
|
let split_info = self.calculate_split_position_using_breaking_strategy(
|
||||||
SplitOptions::empty()) {
|
character_breaking_strategy,
|
||||||
None => None,
|
max_inline_size,
|
||||||
Some(split_info) => {
|
SplitOptions::empty())?;
|
||||||
match split_info.inline_start {
|
|
||||||
None => None,
|
let split = split_info.inline_start?;
|
||||||
Some(split) => {
|
Some(TruncationResult {
|
||||||
Some(TruncationResult {
|
split: split,
|
||||||
split: split,
|
text_run: split_info.text_run.clone(),
|
||||||
text_run: split_info.text_run.clone(),
|
})
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A helper method that uses the breaking strategy described by `slice_iterator` (at present,
|
/// A helper method that uses the breaking strategy described by `slice_iterator` (at present,
|
||||||
|
|
|
@ -339,12 +339,7 @@ impl PropertyAnimation {
|
||||||
longhand,
|
longhand,
|
||||||
old_style,
|
old_style,
|
||||||
new_style,
|
new_style,
|
||||||
);
|
)?;
|
||||||
|
|
||||||
let animated_property = match animated_property {
|
|
||||||
Some(p) => p,
|
|
||||||
None => return None,
|
|
||||||
};
|
|
||||||
|
|
||||||
let property_animation = PropertyAnimation {
|
let property_animation = PropertyAnimation {
|
||||||
property: animated_property,
|
property: animated_property,
|
||||||
|
|
|
@ -169,10 +169,8 @@ impl<E: TElement> StyleBloom<E> {
|
||||||
/// Pop the last element in the bloom filter and return it.
|
/// Pop the last element in the bloom filter and return it.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn pop(&mut self) -> Option<E> {
|
fn pop(&mut self) -> Option<E> {
|
||||||
let (popped_element, num_hashes) = match self.elements.pop() {
|
let PushedElement { element, num_hashes } = self.elements.pop()?;
|
||||||
None => return None,
|
let popped_element = *element;
|
||||||
Some(x) => (*x.element, x.num_hashes),
|
|
||||||
};
|
|
||||||
|
|
||||||
// Verify that the pushed hashes match the ones we'd get from the element.
|
// Verify that the pushed hashes match the ones we'd get from the element.
|
||||||
let mut expected_hashes = vec![];
|
let mut expected_hashes = vec![];
|
||||||
|
|
|
@ -153,10 +153,7 @@ where
|
||||||
K: Borrow<Q>,
|
K: Borrow<Q>,
|
||||||
Q: PrecomputedHash + Hash + Eq,
|
Q: PrecomputedHash + Hash + Eq,
|
||||||
{
|
{
|
||||||
let index = match self.index.iter().position(|k| k.borrow() == key) {
|
let index = self.index.iter().position(|k| k.borrow() == key)?;
|
||||||
Some(p) => p,
|
|
||||||
None => return None,
|
|
||||||
};
|
|
||||||
self.index.remove(index);
|
self.index.remove(index);
|
||||||
self.values.remove(key)
|
self.values.remove(key)
|
||||||
}
|
}
|
||||||
|
@ -194,10 +191,7 @@ where
|
||||||
type Item = (&'a K, &'a V);
|
type Item = (&'a K, &'a V);
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
let key = match self.inner.index.get(self.pos) {
|
let key = self.inner.index.get(self.pos)?;
|
||||||
Some(k) => k,
|
|
||||||
None => return None,
|
|
||||||
};
|
|
||||||
|
|
||||||
self.pos += 1;
|
self.pos += 1;
|
||||||
let value = &self.inner.values[key];
|
let value = &self.inner.values[key];
|
||||||
|
|
|
@ -78,14 +78,10 @@ where
|
||||||
|
|
||||||
fn next(&mut self) -> Option<N> {
|
fn next(&mut self) -> Option<N> {
|
||||||
loop {
|
loop {
|
||||||
match self.0.next() {
|
let n = self.0.next()?;
|
||||||
Some(n) => {
|
// Filter out nodes that layout should ignore.
|
||||||
// Filter out nodes that layout should ignore.
|
if n.is_text_node() || n.is_element() {
|
||||||
if n.is_text_node() || n.is_element() {
|
return Some(n)
|
||||||
return Some(n)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => return None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,13 +96,9 @@ where
|
||||||
type Item = N;
|
type Item = N;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<N> {
|
fn next(&mut self) -> Option<N> {
|
||||||
match self.0.take() {
|
let n = self.0.take()?;
|
||||||
Some(n) => {
|
self.0 = n.next_sibling();
|
||||||
self.0 = n.next_sibling();
|
Some(n)
|
||||||
Some(n)
|
|
||||||
}
|
|
||||||
None => None,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,11 +116,7 @@ where
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn next(&mut self) -> Option<N> {
|
fn next(&mut self) -> Option<N> {
|
||||||
let prev = match self.previous.take() {
|
let prev = self.previous.take()?;
|
||||||
None => return None,
|
|
||||||
Some(n) => n,
|
|
||||||
};
|
|
||||||
|
|
||||||
self.previous = prev.next_in_preorder(Some(self.scope));
|
self.previous = prev.next_in_preorder(Some(self.scope));
|
||||||
self.previous
|
self.previous
|
||||||
}
|
}
|
||||||
|
|
|
@ -428,10 +428,7 @@ impl<'lb> GeckoXBLBinding<'lb> {
|
||||||
if !binding.anon_content().is_null() {
|
if !binding.anon_content().is_null() {
|
||||||
return Some(binding);
|
return Some(binding);
|
||||||
}
|
}
|
||||||
binding = match binding.base_binding() {
|
binding = binding.base_binding()?;
|
||||||
Some(b) => b,
|
|
||||||
None => return None,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1006,20 +1003,14 @@ impl<'le> TElement for GeckoElement<'le> {
|
||||||
|
|
||||||
fn closest_non_native_anonymous_ancestor(&self) -> Option<Self> {
|
fn closest_non_native_anonymous_ancestor(&self) -> Option<Self> {
|
||||||
debug_assert!(self.is_native_anonymous());
|
debug_assert!(self.is_native_anonymous());
|
||||||
let mut parent = match self.traversal_parent() {
|
let mut parent = self.traversal_parent()?;
|
||||||
Some(e) => e,
|
|
||||||
None => return None,
|
|
||||||
};
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
if !parent.is_native_anonymous() {
|
if !parent.is_native_anonymous() {
|
||||||
return Some(parent);
|
return Some(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
parent = match parent.traversal_parent() {
|
parent = parent.traversal_parent()?;
|
||||||
Some(p) => p,
|
|
||||||
None => return None,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1054,16 +1045,10 @@ impl<'le> TElement for GeckoElement<'le> {
|
||||||
|
|
||||||
fn get_smil_override(&self) -> Option<ArcBorrow<Locked<PropertyDeclarationBlock>>> {
|
fn get_smil_override(&self) -> Option<ArcBorrow<Locked<PropertyDeclarationBlock>>> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let slots = match self.get_extended_slots() {
|
let slots = self.get_extended_slots()?;
|
||||||
Some(s) => s,
|
|
||||||
None => return None,
|
|
||||||
};
|
|
||||||
|
|
||||||
let base_declaration: &structs::DeclarationBlock =
|
let base_declaration: &structs::DeclarationBlock =
|
||||||
match slots.mSMILOverrideStyleDeclaration.mRawPtr.as_ref() {
|
slots.mSMILOverrideStyleDeclaration.mRawPtr.as_ref()?;
|
||||||
Some(decl) => decl,
|
|
||||||
None => return None,
|
|
||||||
};
|
|
||||||
|
|
||||||
assert_eq!(base_declaration.mType, structs::StyleBackendType_Servo);
|
assert_eq!(base_declaration.mType, structs::StyleBackendType_Servo);
|
||||||
let declaration: &structs::ServoDeclarationBlock =
|
let declaration: &structs::ServoDeclarationBlock =
|
||||||
|
@ -1074,11 +1059,7 @@ impl<'le> TElement for GeckoElement<'le> {
|
||||||
base_declaration as *const structs::DeclarationBlock
|
base_declaration as *const structs::DeclarationBlock
|
||||||
);
|
);
|
||||||
|
|
||||||
let raw: &structs::RawServoDeclarationBlock =
|
let raw: &structs::RawServoDeclarationBlock = declaration.mRaw.mRawPtr.as_ref()?;
|
||||||
match declaration.mRaw.mRawPtr.as_ref() {
|
|
||||||
Some(decl) => decl,
|
|
||||||
None => return None,
|
|
||||||
};
|
|
||||||
|
|
||||||
Some(Locked::<PropertyDeclarationBlock>::as_arc(
|
Some(Locked::<PropertyDeclarationBlock>::as_arc(
|
||||||
&*(&raw as *const &structs::RawServoDeclarationBlock)
|
&*(&raw as *const &structs::RawServoDeclarationBlock)
|
||||||
|
|
|
@ -127,10 +127,7 @@ impl<'a, E> ElementWrapper<'a, E>
|
||||||
if lang.is_some() {
|
if lang.is_some() {
|
||||||
return lang;
|
return lang;
|
||||||
}
|
}
|
||||||
match current.parent_element() {
|
current = current.parent_element()?;
|
||||||
Some(parent) => current = parent,
|
|
||||||
None => return None,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,20 +102,16 @@ impl RuleCache {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let rules = match builder_with_early_props.rules {
|
let rules = builder_with_early_props.rules.as_ref()?;
|
||||||
Some(ref rules) => rules,
|
let cached_values = self.map.get(rules)?;
|
||||||
None => return None,
|
|
||||||
};
|
|
||||||
|
|
||||||
self.map.get(rules).and_then(|cached_values| {
|
for &(ref conditions, ref values) in cached_values.iter() {
|
||||||
for &(ref conditions, ref values) in cached_values.iter() {
|
if conditions.matches(builder_with_early_props) {
|
||||||
if conditions.matches(builder_with_early_props) {
|
debug!("Using cached reset style with conditions {:?}", conditions);
|
||||||
debug!("Using cached reset style with conditions {:?}", conditions);
|
return Some(&**values)
|
||||||
return Some(&**values)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
None
|
}
|
||||||
})
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Inserts a node into the rules cache if possible.
|
/// Inserts a node into the rules cache if possible.
|
||||||
|
|
|
@ -376,11 +376,7 @@ where
|
||||||
originating_element_style.style(),
|
originating_element_style.style(),
|
||||||
pseudo,
|
pseudo,
|
||||||
VisitedHandlingMode::AllLinksUnvisited
|
VisitedHandlingMode::AllLinksUnvisited
|
||||||
);
|
)?;
|
||||||
let rules = match rules {
|
|
||||||
Some(rules) => rules,
|
|
||||||
None => return None,
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut visited_rules = None;
|
let mut visited_rules = None;
|
||||||
if originating_element_style.style().visited_style().is_some() {
|
if originating_element_style.style().visited_style().is_some() {
|
||||||
|
|
|
@ -80,10 +80,7 @@ where
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
loop {
|
loop {
|
||||||
if self.current.is_none() {
|
if self.current.is_none() {
|
||||||
let next_origin = match self.origins.next() {
|
let next_origin = self.origins.next()?;
|
||||||
Some(o) => o,
|
|
||||||
None => return None,
|
|
||||||
};
|
|
||||||
|
|
||||||
self.current =
|
self.current =
|
||||||
Some((next_origin, self.collections.borrow_for_origin(&next_origin).iter()));
|
Some((next_origin, self.collections.borrow_for_origin(&next_origin).iter()));
|
||||||
|
@ -238,10 +235,7 @@ where
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let potential_sheet = match self.iter.next() {
|
let potential_sheet = self.iter.next()?;
|
||||||
Some(s) => s,
|
|
||||||
None => return None,
|
|
||||||
};
|
|
||||||
|
|
||||||
let dirty = mem::replace(&mut potential_sheet.dirty, false);
|
let dirty = mem::replace(&mut potential_sheet.dirty, false);
|
||||||
if dirty {
|
if dirty {
|
||||||
|
|
|
@ -89,10 +89,7 @@ impl Iterator for OriginSetIterator {
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Origin> {
|
fn next(&mut self) -> Option<Origin> {
|
||||||
loop {
|
loop {
|
||||||
let origin = match Origin::from_index(self.cur) {
|
let origin = Origin::from_index(self.cur)?;
|
||||||
Some(origin) => origin,
|
|
||||||
None => return None,
|
|
||||||
};
|
|
||||||
|
|
||||||
self.cur += 1;
|
self.cur += 1;
|
||||||
|
|
||||||
|
@ -184,10 +181,7 @@ impl<'a, T> Iterator for PerOriginIter<'a, T> where T: 'a {
|
||||||
type Item = (&'a T, Origin);
|
type Item = (&'a T, Origin);
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
let origin = match Origin::from_index(self.cur) {
|
let origin = Origin::from_index(self.cur)?;
|
||||||
Some(origin) => origin,
|
|
||||||
None => return None,
|
|
||||||
};
|
|
||||||
|
|
||||||
self.cur += if self.rev { -1 } else { 1 };
|
self.cur += if self.rev { -1 } else { 1 };
|
||||||
|
|
||||||
|
@ -211,10 +205,7 @@ impl<'a, T> Iterator for PerOriginIterMut<'a, T> where T: 'a {
|
||||||
type Item = (&'a mut T, Origin);
|
type Item = (&'a mut T, Origin);
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
let origin = match Origin::from_index(self.cur) {
|
let origin = Origin::from_index(self.cur)?;
|
||||||
Some(origin) => origin,
|
|
||||||
None => return None,
|
|
||||||
};
|
|
||||||
|
|
||||||
self.cur += 1;
|
self.cur += 1;
|
||||||
|
|
||||||
|
|
|
@ -196,11 +196,7 @@ impl<'a> Iterator for DocumentCascadeDataIter<'a> {
|
||||||
type Item = (&'a CascadeData, Origin);
|
type Item = (&'a CascadeData, Origin);
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
let (_, origin) = match self.iter.next() {
|
let (_, origin) = self.iter.next()?;
|
||||||
Some(o) => o,
|
|
||||||
None => return None,
|
|
||||||
};
|
|
||||||
|
|
||||||
Some((self.cascade_data.borrow_for_origin(origin), origin))
|
Some((self.cascade_data.borrow_for_origin(origin), origin))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -145,10 +145,7 @@ fn to_css_identifier(mut camel_case: &str) -> String {
|
||||||
|
|
||||||
/// Given "FooBar", returns "Foo" and sets `camel_case` to "Bar".
|
/// Given "FooBar", returns "Foo" and sets `camel_case` to "Bar".
|
||||||
fn split_camel_segment<'input>(camel_case: &mut &'input str) -> Option<&'input str> {
|
fn split_camel_segment<'input>(camel_case: &mut &'input str) -> Option<&'input str> {
|
||||||
let index = match camel_case.chars().next() {
|
let index = camel_case.chars().next()?.len_utf8();
|
||||||
None => return None,
|
|
||||||
Some(ch) => ch.len_utf8(),
|
|
||||||
};
|
|
||||||
let end_position = camel_case[index..]
|
let end_position = camel_case[index..]
|
||||||
.find(char::is_uppercase)
|
.find(char::is_uppercase)
|
||||||
.map_or(camel_case.len(), |pos| index + pos);
|
.map_or(camel_case.len(), |pos| index + pos);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue