diff --git a/components/style/properties/declaration_block.rs b/components/style/properties/declaration_block.rs index ad5aa75e8f2..7d1e2f3aa32 100644 --- a/components/style/properties/declaration_block.rs +++ b/components/style/properties/declaration_block.rs @@ -138,56 +138,9 @@ impl<'a> DoubleEndedIterator for DeclarationImportanceIterator<'a> { } } -/// Iterator over `PropertyDeclaration` for Importance::Normal. -/// -/// TODO(emilio): This should be replaced by `impl Trait`, returning a -/// filter()ed iterator when available instead, and all the boilerplate below -/// should go. -pub struct NormalDeclarationIterator<'a>(DeclarationImportanceIterator<'a>); - -impl<'a> NormalDeclarationIterator<'a> { - #[inline] - fn new(declarations: &'a [PropertyDeclaration], important: &'a SmallBitVec) -> Self { - NormalDeclarationIterator( - DeclarationImportanceIterator::new(declarations, important) - ) - } -} - -impl<'a> Iterator for NormalDeclarationIterator<'a> { - type Item = &'a PropertyDeclaration; - - #[inline] - fn next(&mut self) -> Option { - loop { - let (decl, importance) = self.0.iter.next()?; - if !importance { - return Some(decl); - } - } - } - - #[inline] - fn size_hint(&self) -> (usize, Option) { - self.0.iter.size_hint() - } -} - -impl<'a> DoubleEndedIterator for NormalDeclarationIterator<'a> { - #[inline] - fn next_back(&mut self) -> Option { - loop { - let (decl, importance) = self.0.iter.next_back()?; - if !importance { - return Some(decl); - } - } - } -} - /// Iterator for AnimationValue to be generated from PropertyDeclarationBlock. pub struct AnimationValueIterator<'a, 'cx, 'cx_a:'cx> { - iter: NormalDeclarationIterator<'a>, + iter: DeclarationImportanceIterator<'a>, context: &'cx mut Context<'cx_a>, default_values: &'a ComputedValues, /// Custom properties in a keyframe if exists. @@ -202,7 +155,7 @@ impl<'a, 'cx, 'cx_a:'cx> AnimationValueIterator<'a, 'cx, 'cx_a> { extra_custom_properties: Option<&'a Arc<::custom_properties::CustomPropertiesMap>>, ) -> AnimationValueIterator<'a, 'cx, 'cx_a> { AnimationValueIterator { - iter: declarations.normal_declaration_iter(), + iter: declarations.declaration_importance_iter(), context, default_values, extra_custom_properties, @@ -215,7 +168,11 @@ impl<'a, 'cx, 'cx_a:'cx> Iterator for AnimationValueIterator<'a, 'cx, 'cx_a> { #[inline] fn next(&mut self) -> Option { loop { - let decl = self.iter.next()?; + let (decl, importance) = self.iter.next()?; + + if importance.important() { + continue; + } let animation = AnimationValue::from_declaration( decl, @@ -287,8 +244,12 @@ impl PropertyDeclarationBlock { /// Iterate over `PropertyDeclaration` for Importance::Normal #[inline] - pub fn normal_declaration_iter(&self) -> NormalDeclarationIterator { - NormalDeclarationIterator::new(&self.declarations, &self.declarations_importance) + pub fn normal_declaration_iter<'a>( + &'a self, + ) -> impl DoubleEndedIterator { + self.declaration_importance_iter() + .filter(|(_, importance)| !importance.important()) + .map(|(declaration, _)| declaration) } /// Return an iterator of (AnimatableLonghand, AnimationValue).