Skip to content

Truly independent web browser

LibWeb: Walk the effects of an installation in the order of its rows

Andreas Klingdf785f4a9a37
diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/install.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/install.rs
index 95b13949946..db73b325856 100644
--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/install.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/install.rs
@@ -92,9 +92,6 @@ pub(crate) struct EffectsIndex(u32);
pub(crate) struct StyleInstallation {
pub(crate) swaps: Vec<StyleSwap>,
pub(crate) effects: Vec<InstalledElementEffects>,
- /// The indices of the effects, sorted by the elements they are of, for the render side to find an element's, or
- /// none where the effects are sorted by their elements already.
- effects_by_node: Vec<EffectsIndex>,
pub(crate) document_damage: u32,
/// The records the elements and their pseudo-elements move away from, which their moves and effects read, pinned
/// until the host ends the transaction.
@@ -106,20 +103,9 @@ pub(crate) struct StyleInstallation {
impl StyleInstallation {
/// The effects of `node`, where its style moves.
+ #[cfg(test)]
pub(crate) fn effects_of(&self, node: StyleNodeID) -> Option<&InstalledElementEffects> {
- if self.effects_by_node.is_empty() {
- let index = self
- .effects
- .binary_search_by_key(&node, InstalledElementEffects::node)
- .ok()?;
- return Some(&self.effects[index]);
- }
- let index = self
- .effects_by_node
- .binary_search_by_key(&node, |&EffectsIndex(index)| self.effects[index as usize].node())
- .ok()?;
- let EffectsIndex(index) = self.effects_by_node[index];
- Some(&self.effects[index as usize])
+ self.effects.iter().find(|effects| effects.node() == node)
}
/// Takes what the main thread does, leaving the records the installation pinned, which stay pinned until the host
@@ -199,11 +185,7 @@ impl StyleInstallation {
/// Keeps the effects of only the elements the main thread has anything to do for beside swapping in their styles.
pub(crate) fn keep_effects_with_host_work(&mut self) {
- let before = self.effects.len();
self.effects.retain(InstalledElementEffects::has_host_work);
- if self.effects.len() != before {
- self.sort_effects_by_node();
- }
}
/// Ends the element `node`, whose styles the installation noted from the swap `first_swap` on. The elements whose
@@ -219,20 +201,6 @@ impl StyleInstallation {
/// Ends the installation: what all its moves damage is `document_damage`.
fn finish(&mut self, document_damage: u32) {
self.document_damage = document_damage;
- self.sort_effects_by_node();
- }
-
- /// Indexes the effects by their elements, where they are not sorted by them already.
- fn sort_effects_by_node(&mut self) {
- self.effects_by_node.clear();
- if self.effects.is_sorted_by(|a, b| a.node() < b.node()) {
- return;
- }
- let count = u32::try_from(self.effects.len()).expect("an installation's effects fit their index");
- self.effects_by_node = (0..count).map(EffectsIndex).collect();
- let effects = &self.effects;
- self.effects_by_node
- .sort_unstable_by_key(|&EffectsIndex(index)| effects[index as usize].node());
}
}
diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/install_scratch.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/install_scratch.rs
index dcfd95454c4..393f9b91caa 100644
--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/install_scratch.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/install_scratch.rs
@@ -226,53 +226,4 @@ mod tests {
scratch.order(tree, nodes[0], [nodes[0], nodes[1]]);
assert_eq!(scratch.ordered, [nodes[0], nodes[1]]);
}
-
- #[test]
- fn finds_the_effects_of_each_element_in_tree_order_or_not() {
- let (mut engine, nodes) = document_with_a_late_first_child();
- let children = &nodes[1..];
- for class_present in [true, false] {
- match class_present {
- true => add_class(&mut engine, nodes[0], "x"),
- false => remove_class(&mut engine, nodes[0], "x"),
- }
- run_style_update(&mut engine, nodes[0]);
- let installation = engine.take_installation();
- let effects: Vec<_> = installation.effects.iter().map(|effects| effects.node()).collect();
- assert_eq!(effects, children, "effects are in tree order");
- for &child in children {
- assert_eq!(
- installation.effects_of(child).map(|effects| effects.node()),
- Some(child)
- );
- }
- assert!(installation.effects_of(nodes[0]).is_none());
- }
-
- // Where the elements stand in the order of their identities, the effects are found as well.
- add_class(&mut engine, nodes[2], "x");
- let grandchildren = allocate_nodes(&mut engine, 2);
- engine.record_tree_delta(grandchildren[0], None, Some(relations(Some(nodes[2]), None, None)));
- engine.record_tree_delta(
- grandchildren[1],
- None,
- Some(relations(Some(nodes[2]), Some(grandchildren[0]), None)),
- );
- for &grandchild in &grandchildren {
- set_tag(&mut engine, grandchild, "div");
- }
- run_style_update(&mut engine, nodes[0]);
- engine.take_installation();
- remove_class(&mut engine, nodes[2], "x");
- run_style_update(&mut engine, nodes[0]);
- let installation = engine.take_installation();
- let effects: Vec<_> = installation.effects.iter().map(|effects| effects.node()).collect();
- assert_eq!(effects, grandchildren);
- for &grandchild in &grandchildren {
- assert_eq!(
- installation.effects_of(grandchild).map(|effects| effects.node()),
- Some(grandchild)
- );
- }
- }
}
diff --git a/Libraries/LibWeb/Rust/src/css/style/style_job.rs b/Libraries/LibWeb/Rust/src/css/style/style_job.rs
index 9d5a15ca132..0a057672f14 100644
--- a/Libraries/LibWeb/Rust/src/css/style/style_job.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/style_job.rs
@@ -266,13 +266,24 @@ impl StyleJobAnswer {
/// How the boxes of `node`, an element whose style record the transaction installed, take it: they are built
/// again from the root the move names, or the host installs it where they take the composition of its animations, or
- /// appear or go.
- pub(crate) fn element_install(&self, node: StyleNodeID) -> crate::layout::ElementInstall {
+ /// appear or go. Asked of the elements of the rows in their order, which is that of the effects, as `next_effects`
+ /// says it has come to.
+ pub(crate) fn element_install(
+ &self,
+ node: StyleNodeID,
+ next_effects: &std::cell::Cell<usize>,
+ ) -> crate::layout::ElementInstall {
use super::bridge::MainEffects;
use crate::layout::ElementInstall;
- let Some(row) = self.installation_for_host.effects_of(node) else {
+ let Some(row) = self
+ .installation_for_host
+ .effects
+ .get(next_effects.get())
+ .filter(|row| row.node() == node)
+ else {
return ElementInstall::Boxes;
};
+ next_effects.set(next_effects.get() + 1);
if row
.effects
.intersects(MainEffects::ANIMATED | MainEffects::DISPLAY_NONE_FLIP)
@@ -285,6 +296,11 @@ impl StyleJobAnswer {
}
}
+ /// How many elements have effects.
+ pub(crate) fn effects_count(&self) -> usize {
+ self.installation_for_host.effects.len()
+ }
+
/// Notes `styled`, what the render side installed of the transaction's style rows in `arena`.
pub(crate) fn note_styled(&mut self, styled: crate::layout::StyledRows, arena: &crate::layout::LayoutNodeArena) {
debug_assert!(
diff --git a/Libraries/LibWeb/Rust/src/render_state.rs b/Libraries/LibWeb/Rust/src/render_state.rs
index ac681eb9cc6..162304d6a3d 100644
--- a/Libraries/LibWeb/Rust/src/render_state.rs
+++ b/Libraries/LibWeb/Rust/src/render_state.rs
@@ -231,7 +231,15 @@ impl RenderState {
answer.note_host_styled_boxes(arena);
let work = OwedHostWork::default();
arena.queue_box_presence();
- let styled = arena.install_styles(HostCalls(&work), answer.rows(), |node| answer.element_install(node));
+ let next_effects = std::cell::Cell::new(0);
+ let styled = arena.install_styles(HostCalls(&work), answer.rows(), |node| {
+ answer.element_install(node, &next_effects)
+ });
+ assert_eq!(
+ next_effects.get(),
+ answer.effects_count(),
+ "the rows and the effects of an installation stand in one order"
+ );
let host_work = work.resolve(arena);
self.engine_mut().end_reinheriting_for_install();
if !host_work.is_empty() {