style: Clean up cascade rule iteration. r=nordzilla

The current API was pretty awkward as a result of two things:

 * Not being able to create empty iterators for smallbitvec.
 * We used to call the `F` function multiple times, but turns out that
   collecting the declarations in a SmallVec was a perf win.

So clean this up so that it looks more similar to other APIs, taking an
iterator directly.

This is a bit more code, but hopefully easier to understand (and also hopefully
easier to optimize).

The motivation for this work is that I plan to investigate rebasing / landing
https://github.com/servo/servo/pull/20151, and I don't want more instantiations
of apply_declarations and such.

Differential Revision: https://phabricator.services.mozilla.com/D74369
This commit is contained in:
Emilio Cobos Álvarez 2020-05-11 21:33:31 +00:00
parent 6bae0b99ca
commit ec6ecf7d21
4 changed files with 105 additions and 71 deletions

View file

@ -110,9 +110,17 @@ pub struct DeclarationImportanceIterator<'a> {
iter: Zip<Iter<'a, PropertyDeclaration>, smallbitvec::Iter<'a>>,
}
impl<'a> Default for DeclarationImportanceIterator<'a> {
fn default() -> Self {
Self {
iter: [].iter().zip(smallbitvec::Iter::default()),
}
}
}
impl<'a> DeclarationImportanceIterator<'a> {
/// Constructor.
pub fn new(declarations: &'a [PropertyDeclaration], important: &'a SmallBitVec) -> Self {
fn new(declarations: &'a [PropertyDeclaration], important: &'a SmallBitVec) -> Self {
DeclarationImportanceIterator {
iter: declarations.iter().zip(important.iter()),
}