servo: Merge #19538 - Use ? in Option more often (from emilio:questions-questions-questions); r=mbrubeck

Source-Repo: https://github.com/servo/servo
Source-Revision: 548028fd07d85dbbbd0511386f88ea19825dc258

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 4599b24e3d0dbd27d08d9232272f98c0c36cecd7
This commit is contained in:
Emilio Cobos Álvarez 2017-12-09 13:58:25 -06:00
Родитель 0eb71bbd9a
Коммит d6ec9e4c13
8 изменённых файлов: 25 добавлений и 62 удалений

Просмотреть файл

@ -167,10 +167,7 @@ impl<'a> Iterator for FullyActiveBrowsingContextsIterator<'a> {
type Item = &'a BrowsingContext;
fn next(&mut self) -> Option<&'a BrowsingContext> {
loop {
let browsing_context_id = match self.stack.pop() {
Some(browsing_context_id) => browsing_context_id,
None => return None,
};
let browsing_context_id = self.stack.pop()?;
let browsing_context = match self.browsing_contexts.get(&browsing_context_id) {
Some(browsing_context) => browsing_context,
None => {
@ -212,10 +209,7 @@ impl<'a> Iterator for AllBrowsingContextsIterator<'a> {
fn next(&mut self) -> Option<&'a BrowsingContext> {
let pipelines = self.pipelines;
loop {
let browsing_context_id = match self.stack.pop() {
Some(browsing_context_id) => browsing_context_id,
None => return None,
};
let browsing_context_id = self.stack.pop()?;
let browsing_context = match self.browsing_contexts.get(&browsing_context_id) {
Some(browsing_context) => browsing_context,
None => {

Просмотреть файл

@ -69,11 +69,7 @@ impl FontHandle {
/// Cache all the data needed for basic horizontal kerning. This is used only as a fallback or
/// fast path (when the GPOS table is missing or unnecessary) so it needn't handle every case.
fn find_h_kern_subtable(&self) -> Option<CachedKernTable> {
let font_table = match self.table_for_tag(KERN) {
Some(table) => table,
None => return None
};
let font_table = self.table_for_tag(KERN)?;
let mut result = CachedKernTable {
font_table: font_table,
pair_data_range: 0..0,

Просмотреть файл

@ -149,10 +149,7 @@ impl<'a> Iterator for CharacterSliceIterator<'a> {
// inline(always) due to the inefficient rt failures messing up inline heuristics, I think.
#[inline(always)]
fn next(&mut self) -> Option<TextRunSlice<'a>> {
let glyph_run = match self.glyph_run {
None => return None,
Some(glyph_run) => glyph_run,
};
let glyph_run = self.glyph_run?;
debug_assert!(!self.range.is_empty());
let byte_start = self.range.begin();

Просмотреть файл

@ -1051,13 +1051,9 @@ impl<'a, T, S> Iterator for Intersection<'a, T, S>
fn next(&mut self) -> Option<&'a T> {
loop {
match self.iter.next() {
None => return None,
Some(elt) => {
if self.other.contains(elt) {
return Some(elt);
}
}
let elt = self.iter.next()?;
if self.other.contains(elt) {
return Some(elt);
}
}
}
@ -1091,13 +1087,9 @@ impl<'a, T, S> Iterator for Difference<'a, T, S>
fn next(&mut self) -> Option<&'a T> {
loop {
match self.iter.next() {
None => return None,
Some(elt) => {
if !self.other.contains(elt) {
return Some(elt);
}
}
let elt = self.iter.next()?;
if !self.other.contains(elt) {
return Some(elt);
}
}
}

Просмотреть файл

@ -479,10 +479,7 @@ impl HttpCache {
return None;
}
let entry_key = CacheKey::new(request.clone());
let resources = match self.entries.get(&entry_key) {
Some(ref resources) => resources.clone(),
None => return None,
};
let resources = self.entries.get(&entry_key)?.clone();
let mut candidates = vec![];
for cached_resource in resources.iter() {
let mut can_be_constructed = true;

Просмотреть файл

@ -75,10 +75,7 @@ impl VirtualMethods for HTMLLegendElement {
impl HTMLLegendElementMethods for HTMLLegendElement {
// https://html.spec.whatwg.org/multipage/#dom-legend-form
fn GetForm(&self) -> Option<DomRoot<HTMLFormElement>> {
let parent = match self.upcast::<Node>().GetParentElement() {
Some(parent) => parent,
None => return None,
};
let parent = self.upcast::<Node>().GetParentElement()?;
if parent.is::<HTMLFieldSetElement>() {
return self.form_owner();
}

Просмотреть файл

@ -140,14 +140,9 @@ impl<'a> Iterator for NormalDeclarationIterator<'a> {
fn next(&mut self) -> Option<Self::Item> {
loop {
let next = self.0.iter.next();
match next {
Some((decl, importance)) => {
if !importance {
return Some(decl);
}
},
None => return None,
let (decl, importance) = self.0.iter.next()?;
if !importance {
return Some(decl);
}
}
}
@ -171,7 +166,7 @@ impl<'a, 'cx, 'cx_a:'cx> AnimationValueIterator<'a, 'cx, 'cx_a> {
declarations: &'a PropertyDeclarationBlock,
context: &'cx mut Context<'cx_a>,
default_values: &'a ComputedValues,
extra_custom_properties: Option<&'a Arc<::custom_properties::CustomPropertiesMap>>,
extra_custom_properties: Option<&'a Arc<::custom_properties::CustomPropertiesMap>>,
) -> AnimationValueIterator<'a, 'cx, 'cx_a> {
AnimationValueIterator {
iter: declarations.normal_declaration_iter(),
@ -187,11 +182,7 @@ impl<'a, 'cx, 'cx_a:'cx> Iterator for AnimationValueIterator<'a, 'cx, 'cx_a> {
#[inline]
fn next(&mut self) -> Option<Self::Item> {
loop {
let next = self.iter.next();
let decl = match next {
Some(decl) => decl,
None => return None,
};
let decl = self.iter.next()?;
let animation = AnimationValue::from_declaration(
decl,

Просмотреть файл

@ -850,11 +850,13 @@ impl ShorthandId {
/// Finds and returns an appendable value for the given declarations.
///
/// Returns the optional appendable value.
pub fn get_shorthand_appendable_value<'a, I>(self,
declarations: I)
-> Option<AppendableValue<'a, I::IntoIter>>
where I: IntoIterator<Item=&'a PropertyDeclaration>,
I::IntoIter: Clone,
pub fn get_shorthand_appendable_value<'a, I>(
self,
declarations: I,
) -> Option<AppendableValue<'a, I::IntoIter>>
where
I: IntoIterator<Item=&'a PropertyDeclaration>,
I::IntoIter: Clone,
{
let declarations = declarations.into_iter();
@ -862,10 +864,7 @@ impl ShorthandId {
let mut declarations2 = declarations.clone();
let mut declarations3 = declarations.clone();
let first_declaration = match declarations2.next() {
Some(declaration) => declaration,
None => return None
};
let first_declaration = declarations2.next()?;
// https://drafts.csswg.org/css-variables/#variables-in-shorthands
if let Some(css) = first_declaration.with_variables_from_shorthand(self) {