Skip to content

Truly independent web browser

LibWeb: Install a prefix relation's changed answers once

Andreas Kling8f3a5a5c6b96
diff --git a/Libraries/LibWeb/Rust/src/css/style/matching.rs b/Libraries/LibWeb/Rust/src/css/style/matching.rs
index a63caf4423d..71be62b888c 100644
--- a/Libraries/LibWeb/Rust/src/css/style/matching.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/matching.rs
@@ -402,7 +402,7 @@ impl RetainedState {
|| dispatch.prefixes().supports_relation(&self.tree, root))
{
let states = caches.states.prepare_program(program);
- let relation = states.relation.take().unwrap_or_else(|| {
+ let mut relation = states.relation.take().unwrap_or_else(|| {
let mut workspace = MatchScratch::default();
let mut evaluator = MatchEvaluator::new(&self.tree, facts)
.with_match_workspace(&mut workspace, selector::MatchEvaluationSide::Current);
diff --git a/Libraries/LibWeb/Rust/src/css/style/prefix/relation.rs b/Libraries/LibWeb/Rust/src/css/style/prefix/relation.rs
index 95c33504b38..355a36c9735 100644
--- a/Libraries/LibWeb/Rust/src/css/style/prefix/relation.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/prefix/relation.rs
@@ -395,7 +395,11 @@ impl PrefixRelation {
+ self.handled_routing_keys.shallow_capacity_bytes();
}
- pub(in crate::css::style) fn install_answers(&self, states: &mut PrefixStates) {
+ /// Install the answers into `states`: every live node's when `states` holds none yet, and
+ /// otherwise the ones the last update changed and its arrivals. Both are installed once: a
+ /// transaction that installs the relation again without an update or a geometry pass would
+ /// otherwise pay the size of that old update again.
+ pub(in crate::css::style) fn install_answers(&mut self, states: &mut PrefixStates) {
if states.relation_answers.is_empty() {
for (position, (&node, entries)) in self.nodes.iter().zip(&self.answers).enumerate() {
if self.live[position] {
@@ -410,6 +414,9 @@ impl PrefixRelation {
states.install_relation_answer(self.nodes[position], &self.answers[position]);
}
}
+ self.changed_answers.clear();
+ self.arrivals.clear();
+ self.refresh_capacity_bytes();
}
/// Whether `node` is one of the live nodes the relation answers for.
diff --git a/Libraries/LibWeb/Rust/src/css/style/tests.rs b/Libraries/LibWeb/Rust/src/css/style/tests.rs
index d691c46e297..fd94b1b6017 100644
--- a/Libraries/LibWeb/Rust/src/css/style/tests.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/tests.rs
@@ -6094,7 +6094,7 @@ fn prefix_relation_copies_only_dispatch_complete_predicates() {
}
discard_transaction(&mut engine);
let before = engine.counters.get(Counter::PrefixCompoundsEvaluated);
- let (_, relation) = test_prefix_relation(&mut engine, nodes[0]);
+ let (_, mut relation) = test_prefix_relation(&mut engine, nodes[0]);
let evaluated = engine.counters.get(Counter::PrefixCompoundsEvaluated) - before;
if additional_tests {
assert!(evaluated > 0);
@@ -6123,7 +6123,7 @@ fn prefix_completion_reuses_positive_and_negative_relation_answers() {
add_feature(&mut engine, nodes[1], LocalFeatureKey::Class(guard));
add_feature(&mut engine, nodes[3], LocalFeatureKey::Class(target));
discard_transaction(&mut engine);
- let (dispatch, relation) = test_prefix_relation(&mut engine, nodes[0]);
+ let (dispatch, mut relation) = test_prefix_relation(&mut engine, nodes[0]);
let facts = engine.facts.primary();
let mut evaluator = MatchEvaluator::new(&engine.tree, facts);
let mut evaluation = PrefixEvaluation::new(
@@ -6448,7 +6448,7 @@ fn prefix_relation_local_fact_cache_separates_predicates_and_tracks_changes() {
);
assert_eq!(relation.changed_answers.len(), nodes.len());
relation.install_answers(&mut states);
- let (_, rebuilt) = test_prefix_relation(&mut engine, nodes[0]);
+ let (_, mut rebuilt) = test_prefix_relation(&mut engine, nodes[0]);
let mut rebuilt_states = PrefixStates::new();
rebuilt.install_answers(&mut rebuilt_states);
for (index, &node) in nodes.iter().enumerate() {