From 063db3580697bb4c804ceef9fb13de4f0f5e8832 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Wed, 13 Sep 2017 19:38:32 -0500 Subject: [PATCH] servo: Merge #18494 - Implement `size_hint` for more iterators (from frewsxcv:frewsxcv-size-hint); r=jdm ``` implement size hint for more iterators because why not we like fast things ``` Source-Repo: https://github.com/servo/servo Source-Revision: bb2030a49314433c1b31f853e4fa50afa241b596 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : fb164a6e8e51ebba14d97ee7600567b3b517dc30 --- servo/components/layout/flow.rs | 4 ++++ servo/components/layout/inline.rs | 4 ++++ servo/components/script/dom/htmlselectelement.rs | 8 ++++++++ servo/components/script/dom/servoparser/mod.rs | 4 ++++ servo/components/style/font_face.rs | 4 ++++ servo/components/style/properties/declaration_block.rs | 4 ++++ servo/components/style/stylesheet_set.rs | 4 ++++ servo/components/style/values/computed/mod.rs | 4 ++++ 8 files changed, 36 insertions(+) diff --git a/servo/components/layout/flow.rs b/servo/components/layout/flow.rs index f4c545ec730b..a2a057614380 100644 --- a/servo/components/layout/flow.rs +++ b/servo/components/layout/flow.rs @@ -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) { + self.iter.size_hint() + } } pub type AbsoluteDescendantOffsetIter<'a> = Zip, IterMut<'a, Au>>; diff --git a/servo/components/layout/inline.rs b/servo/components/layout/inline.rs index f07943fd3218..c38693c33404 100644 --- a/servo/components/layout/inline.rs +++ b/servo/components/layout/inline.rs @@ -979,6 +979,10 @@ impl InlineFlow { self.iter.next() } } + + fn size_hint(&self) -> (usize, Option) { + self.iter.size_hint() + } } // If the bidi embedding direction is opposite the layout direction, lay out this diff --git a/servo/components/script/dom/htmlselectelement.rs b/servo/components/script/dom/htmlselectelement.rs index fd5a864862af..9db953162970 100755 --- a/servo/components/script/dom/htmlselectelement.rs +++ b/servo/components/script/dom/htmlselectelement.rs @@ -440,4 +440,12 @@ impl Iterator for Choice3 Choice3::Third(ref mut k) => k.next(), } } + + fn size_hint(&self) -> (usize, Option) { + match *self { + Choice3::First(ref i) => i.size_hint(), + Choice3::Second(ref j) => j.size_hint(), + Choice3::Third(ref k) => k.size_hint(), + } + } } diff --git a/servo/components/script/dom/servoparser/mod.rs b/servo/components/script/dom/servoparser/mod.rs index 241179ed6244..d0e08664e73a 100644 --- a/servo/components/script/dom/servoparser/mod.rs +++ b/servo/components/script/dom/servoparser/mod.rs @@ -487,6 +487,10 @@ impl Iterator for FragmentParsingResult next.remove_self(); Some(next) } + + fn size_hint(&self) -> (usize, Option) { + self.inner.size_hint() + } } #[derive(HeapSizeOf, JSTraceable, PartialEq)] diff --git a/servo/components/style/font_face.rs b/servo/components/style/font_face.rs index c12934a3b063..30eb242a6d4f 100644 --- a/servo/components/style/font_face.rs +++ b/servo/components/style/font_face.rs @@ -170,6 +170,10 @@ impl Iterator for EffectiveSources { fn next(&mut self) -> Option { self.0.pop() } + + fn size_hint(&self) -> (usize, Option) { + (self.0.len(), Some(self.0.len())) + } } struct FontFaceRuleParser<'a, 'b: 'a> { diff --git a/servo/components/style/properties/declaration_block.rs b/servo/components/style/properties/declaration_block.rs index a87b87fe9db9..15573cc6aefa 100644 --- a/servo/components/style/properties/declaration_block.rs +++ b/servo/components/style/properties/declaration_block.rs @@ -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) { + self.iter.size_hint() + } } impl<'a> DoubleEndedIterator for DeclarationImportanceIterator<'a> { diff --git a/servo/components/style/stylesheet_set.rs b/servo/components/style/stylesheet_set.rs index 328237ccbaec..4b8b177b554f 100644 --- a/servo/components/style/stylesheet_set.rs +++ b/servo/components/style/stylesheet_set.rs @@ -45,6 +45,10 @@ where fn next(&mut self) -> Option { self.0.next().map(|entry| &entry.sheet) } + + fn size_hint(&self) -> (usize, Option) { + self.0.size_hint() + } } /// An iterator over the flattened view of the stylesheet collections. diff --git a/servo/components/style/values/computed/mod.rs b/servo/components/style/values/computed/mod.rs index cad3db03aa74..a6c828b14b80 100644 --- a/servo/components/style/values/computed/mod.rs +++ b/servo/components/style/values/computed/mod.rs @@ -198,6 +198,10 @@ impl<'a, 'cx, 'cx_a: 'cx, S: ToComputedValue + 'a> Iterator for ComputedVecIter< None } } + + fn size_hint(&self) -> (usize, Option) { + (self.values.len(), Some(self.values.len())) + } } /// A trait to represent the conversion between computed and specified values.