Auto merge of #12861 - nox:impl-trait, r=Ms2ger

Clean up some iterators

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12861)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-08-20 13:35:04 -05:00 committed by GitHub
commit 8a75810eba
4 changed files with 12 additions and 46 deletions

View file

@ -31,7 +31,7 @@ use context::LayoutContext;
use display_list_builder::DisplayListBuildState; use display_list_builder::DisplayListBuildState;
use euclid::{Point2D, Rect, Size2D}; use euclid::{Point2D, Rect, Size2D};
use floats::{Floats, SpeculatedFloatPlacement}; use floats::{Floats, SpeculatedFloatPlacement};
use flow_list::{FlowList, FlowListIterator, MutFlowListIterator}; use flow_list::{FlowList, MutFlowListIterator};
use flow_ref::{self, FlowRef, WeakFlowRef}; use flow_ref::{self, FlowRef, WeakFlowRef};
use fragment::{Fragment, FragmentBorderBoxIterator, Overflow, SpecificFragmentInfo}; use fragment::{Fragment, FragmentBorderBoxIterator, Overflow, SpecificFragmentInfo};
use gfx::display_list::{ClippingRegion, StackingContext}; use gfx::display_list::{ClippingRegion, StackingContext};
@ -432,7 +432,7 @@ pub fn base<T: ?Sized + Flow>(this: &T) -> &BaseFlow {
} }
/// Iterates over the children of this immutable flow. /// Iterates over the children of this immutable flow.
pub fn child_iter<'a>(flow: &'a Flow) -> FlowListIterator<'a> { pub fn child_iter<'a>(flow: &'a Flow) -> impl Iterator<Item = &'a Flow> {
base(flow).children.iter() base(flow).children.iter()
} }

View file

@ -13,10 +13,6 @@ pub struct FlowList {
flows: LinkedList<FlowRef>, flows: LinkedList<FlowRef>,
} }
pub struct FlowListIterator<'a> {
it: linked_list::Iter<'a, FlowRef>,
}
pub struct MutFlowListIterator<'a> { pub struct MutFlowListIterator<'a> {
it: linked_list::IterMut<'a, FlowRef>, it: linked_list::IterMut<'a, FlowRef>,
} }
@ -58,10 +54,8 @@ impl FlowList {
/// Provide a forward iterator /// Provide a forward iterator
#[inline] #[inline]
pub fn iter(&self) -> FlowListIterator { pub fn iter<'a>(&'a self) -> impl DoubleEndedIterator<Item = &'a Flow> {
FlowListIterator { self.flows.iter().map(|flow| &**flow)
it: self.flows.iter(),
}
} }
/// Provide a forward iterator with mutable references /// Provide a forward iterator with mutable references
@ -74,7 +68,8 @@ impl FlowList {
/// Provide a forward iterator with FlowRef items /// Provide a forward iterator with FlowRef items
#[inline] #[inline]
pub fn iter_flow_ref_mut<'a>(&'a mut self) -> linked_list::IterMut<'a, FlowRef> { pub fn iter_flow_ref_mut<'a>(&'a mut self)
-> impl DoubleEndedIterator<Item = &'a mut FlowRef> {
self.flows.iter_mut() self.flows.iter_mut()
} }
@ -98,25 +93,6 @@ impl FlowList {
} }
} }
impl<'a> Iterator for FlowListIterator<'a> {
type Item = &'a Flow;
#[inline]
fn next(&mut self) -> Option<&'a Flow> {
self.it.next().map(|x| &**x)
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
self.it.size_hint()
}
}
impl<'a> DoubleEndedIterator for FlowListIterator<'a> {
fn next_back(&mut self) -> Option<&'a Flow> {
self.it.next_back().map(|x| &**x)
}
}
impl<'a> DoubleEndedIterator for MutFlowListIterator<'a> { impl<'a> DoubleEndedIterator for MutFlowListIterator<'a> {
fn next_back(&mut self) -> Option<&'a mut Flow> { fn next_back(&mut self) -> Option<&'a mut Flow> {
self.it.next_back().map(flow_ref::deref_mut) self.it.next_back().map(flow_ref::deref_mut)

View file

@ -4,6 +4,7 @@
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(box_syntax)] #![feature(box_syntax)]
#![feature(conservative_impl_trait)]
#![feature(custom_derive)] #![feature(custom_derive)]
#![feature(nonzero)] #![feature(nonzero)]
#![feature(plugin)] #![feature(plugin)]

View file

@ -14,12 +14,11 @@ use dom::element::{Element, StylePriority};
use dom::node::{Node, NodeDamage, window_from_node}; use dom::node::{Node, NodeDamage, window_from_node};
use dom::window::Window; use dom::window::Window;
use std::ascii::AsciiExt; use std::ascii::AsciiExt;
use std::cell::Ref; use std::ops::Deref;
use std::slice;
use string_cache::Atom; use string_cache::Atom;
use style::parser::ParserContextExtraData; use style::parser::ParserContextExtraData;
use style::properties::{PropertyDeclaration, Shorthand}; use style::properties::{Shorthand, is_supported_property};
use style::properties::{is_supported_property, parse_one_declaration, parse_style_attribute}; use style::properties::{parse_one_declaration, parse_style_attribute};
use style::selector_impl::PseudoElement; use style::selector_impl::PseudoElement;
// http://dev.w3.org/csswg/cssom/#the-cssstyledeclaration-interface // http://dev.w3.org/csswg/cssom/#the-cssstyledeclaration-interface
@ -148,19 +147,9 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
} }
} }
// Step 2.3
// Work around closures not being Clone
#[derive(Clone)]
struct Map<'a, 'b: 'a>(slice::Iter<'a, Ref<'b, PropertyDeclaration>>);
impl<'a, 'b> Iterator for Map<'a, 'b> {
type Item = &'a PropertyDeclaration;
fn next(&mut self) -> Option<Self::Item> {
self.0.next().map(|r| &**r)
}
}
// TODO: important is hardcoded to false because method does not implement it yet // TODO: important is hardcoded to false because method does not implement it yet
let serialized_value = shorthand.serialize_shorthand_value_to_string(Map(list.iter()), false); let serialized_value = shorthand.serialize_shorthand_value_to_string(
list.iter().map(Deref::deref as fn(_) -> _), false);
return DOMString::from(serialized_value); return DOMString::from(serialized_value);
} }