Bug 1728754 - Add layer_order to rules. r=boris

I want to land this separately because we might want to get smarter with
the size of the Rule struct (maybe restricting layer order to a u8 per
scope and packing it with the source order, since 255 layers seem
plenty), but I'd rather do the obvious thing for now.

Depends on D124336

Differential Revision: https://phabricator.services.mozilla.com/D124337
This commit is contained in:
Emilio Cobos Álvarez 2021-09-06 09:54:02 +00:00
Родитель 30f1b8637e
Коммит 13245e72d6
2 изменённых файлов: 24 добавлений и 12 удалений

Просмотреть файл

@ -2004,7 +2004,7 @@ impl CascadeData {
selectors_for_cache_revalidation: SelectorMap::new_without_attribute_bucketing(),
animations: Default::default(),
layer_order: Default::default(),
next_layer_order: 0,
next_layer_order: 1, // 0 reserved for the root scope.
extra_data: ExtraStyleData::default(),
effective_media_query_results: EffectiveMediaQueryResults::new(),
rules_source_order: 0,
@ -2168,6 +2168,7 @@ impl CascadeData {
guard: &SharedRwLockReadGuard,
rebuild_kind: SheetRebuildKind,
current_layer: &mut LayerName,
current_layer_order: u32,
mut precomputed_pseudo_element_decls: Option<&mut PrecomputedPseudoElementDeclarations>,
) -> Result<(), FailedAllocationError>
where
@ -2215,6 +2216,7 @@ impl CascadeData {
hashes,
locked.clone(),
self.rules_source_order,
current_layer_order,
);
if rebuild_kind.should_rebuild_invalidation() {
@ -2352,6 +2354,7 @@ impl CascadeData {
}
let mut layer_names_to_pop = 0;
let mut children_layer_order = current_layer_order;
match *rule {
CssRule::Import(ref lock) => {
if rebuild_kind.should_rebuild_invalidation() {
@ -2370,15 +2373,17 @@ impl CascadeData {
CssRule::Layer(ref lock) => {
use crate::stylesheets::layer_rule::LayerRuleKind;
fn maybe_register_layer(data: &mut CascadeData, layer: &LayerName) {
fn maybe_register_layer(data: &mut CascadeData, layer: &LayerName) -> u32 {
// TODO: Measure what's more common / expensive, if
// layer.clone() or the double hash lookup in the insert
// case.
if data.layer_order.get(layer).is_some() {
return;
if let Some(order) = data.layer_order.get(layer) {
return *order;
}
data.layer_order.insert(layer.clone(), data.next_layer_order);
let order = data.next_layer_order;
data.layer_order.insert(layer.clone(), order);
data.next_layer_order += 1;
order
}
let layer_rule = lock.read_with(guard);
@ -2386,7 +2391,7 @@ impl CascadeData {
LayerRuleKind::Block { ref name, .. } => {
for name in name.layer_names() {
current_layer.0.push(name.clone());
maybe_register_layer(self, &current_layer);
children_layer_order = maybe_register_layer(self, &current_layer);
layer_names_to_pop += 1;
}
}
@ -2414,6 +2419,7 @@ impl CascadeData {
guard,
rebuild_kind,
current_layer,
children_layer_order,
precomputed_pseudo_element_decls.as_deref_mut(),
)?;
}
@ -2458,6 +2464,7 @@ impl CascadeData {
guard,
rebuild_kind,
&mut current_layer,
/* current_layer_order = */ 0,
precomputed_pseudo_element_decls.as_deref_mut(),
)?;
@ -2576,7 +2583,7 @@ impl CascadeData {
}
self.animations.clear();
self.layer_order.clear();
self.next_layer_order = 0;
self.next_layer_order = 1;
self.extra_data.clear();
self.rules_source_order = 0;
self.num_selectors = 0;
@ -2665,6 +2672,9 @@ pub struct Rule {
/// we could repurpose that storage here if we needed to.
pub source_order: u32,
/// The current layer order of this style rule.
pub layer_order: u32,
/// The actual style rule.
#[cfg_attr(
feature = "gecko",
@ -2702,12 +2712,14 @@ impl Rule {
hashes: AncestorHashes,
style_rule: Arc<Locked<StyleRule>>,
source_order: u32,
layer_order: u32,
) -> Self {
Rule {
selector: selector,
hashes: hashes,
style_rule: style_rule,
source_order: source_order,
selector,
hashes,
style_rule,
source_order,
layer_order,
}
}
}

Просмотреть файл

@ -30,7 +30,7 @@ size_of_test!(size_of_pseudo_class, selector_parser::NonTSPseudoClass, 16);
// The size of this is critical to performance on the bloom-basic microbenchmark.
// When iterating over a large Rule array, we want to be able to fast-reject
// selectors (with the inline hashes) with as few cache misses as possible.
size_of_test!(test_size_of_rule, style::stylist::Rule, 32);
size_of_test!(test_size_of_rule, style::stylist::Rule, 40);
// Large pages generate tens of thousands of ComputedValues.
size_of_test!(test_size_of_cv, ComputedValues, 232);