Skip to main content

Module diff

Module diff 

Source
Expand description

Widget-tree diffing: turn an old tree into a new one with a minimal op set.

Given two WidgetTrees whose nodes carry stable WidgetIds, diff produces an ordered Vec<DiffOp> of Insert / Remove / Update / Move operations that, applied in order, transform the old tree’s structure into the new one. This is the reconciliation step a retained backend runs to avoid rebuilding unchanged subtrees.

§Algorithm

Diffing is per-node: for each id present in both trees we compare the child id lists and compute a longest common subsequence (LCS). Children in the LCS keep their relative order for free; children present in both lists but not in the LCS are emitted as Moves; children only in the new list are Inserts; children only in the old list are Removes. A node whose own paint-relevant fields changed is emitted as an Update. Using the LCS keeps the move set minimal (you never move a node that didn’t need moving), which is the property that makes keyed list diffing efficient and stable.

Enums§

DiffOp
A single reconciliation operation produced by diff.

Functions§

diff
Compute the ordered diff that turns old into new.