Skip to content

Commit

Permalink
Implement size_hint for more iterators.
Browse files Browse the repository at this point in the history
```
implement size hint for
more iterators because why
not we like fast things
```
  • Loading branch information
frewsxcv committed Sep 14, 2017
1 parent cad3aff commit 9cd4535
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions components/layout/flow.rs
Expand Up @@ -765,6 +765,10 @@ impl<'a> Iterator for AbsoluteDescendantIter<'a> {
fn next(&mut self) -> Option<&'a mut Flow> {
self.iter.next().map(|info| FlowRef::deref_mut(&mut info.flow))
}

fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
}
}

pub type AbsoluteDescendantOffsetIter<'a> = Zip<AbsoluteDescendantIter<'a>, IterMut<'a, Au>>;
Expand Down
4 changes: 4 additions & 0 deletions components/layout/inline.rs
Expand Up @@ -979,6 +979,10 @@ impl InlineFlow {
self.iter.next()
}
}

fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
}
}

// If the bidi embedding direction is opposite the layout direction, lay out this
Expand Down
8 changes: 8 additions & 0 deletions components/script/dom/htmlselectelement.rs
Expand Up @@ -440,4 +440,12 @@ impl<I, J, K, T> Iterator for Choice3<I, J, K>
Choice3::Third(ref mut k) => k.next(),
}
}

fn size_hint(&self) -> (usize, Option<usize>) {
match *self {
Choice3::First(ref i) => i.size_hint(),
Choice3::Second(ref j) => j.size_hint(),
Choice3::Third(ref k) => k.size_hint(),
}
}
}
4 changes: 4 additions & 0 deletions components/script/dom/servoparser/mod.rs
Expand Up @@ -487,6 +487,10 @@ impl<I> Iterator for FragmentParsingResult<I>
next.remove_self();
Some(next)
}

fn size_hint(&self) -> (usize, Option<usize>) {
self.inner.size_hint()
}
}

#[derive(HeapSizeOf, JSTraceable, PartialEq)]
Expand Down
4 changes: 4 additions & 0 deletions components/style/font_face.rs
Expand Up @@ -170,6 +170,10 @@ impl Iterator for EffectiveSources {
fn next(&mut self) -> Option<Source> {
self.0.pop()
}

fn size_hint(&self) -> (usize, Option<usize>) {
(self.0.len(), Some(self.0.len()))
}
}

struct FontFaceRuleParser<'a, 'b: 'a> {
Expand Down
4 changes: 4 additions & 0 deletions components/style/properties/declaration_block.rs
Expand Up @@ -99,6 +99,10 @@ impl<'a> Iterator for DeclarationImportanceIterator<'a> {
self.iter.next().map(|(decl, important)|
(decl, if important { Importance::Important } else { Importance::Normal }))
}

fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
}
}

impl<'a> DoubleEndedIterator for DeclarationImportanceIterator<'a> {
Expand Down
4 changes: 4 additions & 0 deletions components/style/stylesheet_set.rs
Expand Up @@ -45,6 +45,10 @@ where
fn next(&mut self) -> Option<Self::Item> {
self.0.next().map(|entry| &entry.sheet)
}

fn size_hint(&self) -> (usize, Option<usize>) {
self.0.size_hint()
}
}

/// The validity of the data in a given cascade origin.
Expand Down
4 changes: 4 additions & 0 deletions components/style/values/computed/mod.rs
Expand Up @@ -198,6 +198,10 @@ impl<'a, 'cx, 'cx_a: 'cx, S: ToComputedValue + 'a> Iterator for ComputedVecIter<
None
}
}

fn size_hint(&self) -> (usize, Option<usize>) {
(self.values.len(), Some(self.values.len()))
}
}

/// A trait to represent the conversion between computed and specified values.
Expand Down

0 comments on commit 9cd4535

Please sign in to comment.