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

@ -1318,12 +1318,6 @@ impl Stylist {
use crate::font_metrics::get_metrics_provider_for_product;
let block = declarations.read_with(guards.author);
let iter_declarations = || {
block
.declaration_importance_iter()
.map(|(declaration, _)| (declaration, Origin::Author))
};
let metrics = get_metrics_provider_for_product();
// We don't bother inserting these declarations in the rule tree, since
@ -1332,12 +1326,14 @@ impl Stylist {
// TODO(emilio): Now that we fixed bug 1493420, we should consider
// reversing this as it shouldn't be slow anymore, and should avoid
// generating two instantiations of apply_declarations.
properties::apply_declarations::<E, _, _>(
properties::apply_declarations::<E, _>(
&self.device,
/* pseudo = */ None,
self.rule_tree.root(),
guards,
iter_declarations,
block
.declaration_importance_iter()
.map(|(declaration, _)| (declaration, Origin::Author)),
Some(parent_style),
Some(parent_style),
Some(parent_style),