on master help sign in
Clarify which stack the diffing comments are talking about
dca2045Nick Fitzgerald
src/diff.rs+36−33
@@ -13,11 +13,11 @@ use std::u32;
13// physical DOM node that reflects `old` into something that reflects `new`.
13// physical DOM node that reflects `old` into something that reflects `new`.
14//
14//
15// Upon entry to this function, the physical DOM node must be on the top of the
15// Upon entry to this function, the physical DOM node must be on the top of the
16−// stack:
16+// change list stack:
17//
17//
18// [... node]
18// [... node]
19//
19//
20−// The stack is in the same state when this function exits.
20+// The change list stack is in the same state when this function exits.
21pub(crate) fn diff(
21pub(crate) fn diff(
22 cached_set: &CachedSet,
22 cached_set: &CachedSet,
23 change_list: &mut ChangeListBuilder,
23 change_list: &mut ChangeListBuilder,
@@ -122,11 +122,11 @@ pub(crate) fn diff(
122
122
123// Diff event listeners between `old` and `new`.
123// Diff event listeners between `old` and `new`.
124//
124//
125−// The listeners' node must be on top of the stack:
125+// The listeners' node must be on top of the change list stack:
126//
126//
127// [... node]
127// [... node]
128//
128//
129−// The stack is left unchanged.
129+// The change list stack is left unchanged.
130fn diff_listeners(
130fn diff_listeners(
131 change_list: &mut ChangeListBuilder,
131 change_list: &mut ChangeListBuilder,
132 registry: &mut EventsRegistry,
132 registry: &mut EventsRegistry,
@@ -165,11 +165,11 @@ fn diff_listeners(
165
165
166// Diff a node's attributes.
166// Diff a node's attributes.
167//
167//
168−// The attributes' node must be on top of the stack:
168+// The attributes' node must be on top of the change list stack:
169//
169//
170// [... node]
170// [... node]
171//
171//
172−// The stack is left unchanged.
172+// The change list stack is left unchanged.
173fn diff_attributes(change_list: &mut ChangeListBuilder, old: &[Attribute], new: &[Attribute]) {
173fn diff_attributes(change_list: &mut ChangeListBuilder, old: &[Attribute], new: &[Attribute]) {
174 // Do O(n^2) passes to add/update and remove attributes, since
174 // Do O(n^2) passes to add/update and remove attributes, since
175 // there are almost always very few attributes.
175 // there are almost always very few attributes.
@@ -201,11 +201,12 @@ fn diff_attributes(change_list: &mut ChangeListBuilder, old: &[Attribute], new:
201
201
202// Diff the given set of old and new children.
202// Diff the given set of old and new children.
203//
203//
204−// The parent must be on top of the stack when this function is entered:
204+// The parent must be on top of the change list stack when this function is
205+// entered:
205//
206//
206// [... parent]
207// [... parent]
207//
208//
208−// The stack is in the same state when this function returns.
209+// the change list stack is in the same state when this function returns.
209fn diff_children(
210fn diff_children(
210 cached_set: &CachedSet,
211 cached_set: &CachedSet,
211 change_list: &mut ChangeListBuilder,
212 change_list: &mut ChangeListBuilder,
@@ -262,11 +263,12 @@ fn diff_children(
262//
263//
263// https://github.com/infernojs/inferno/blob/36fd96/packages/inferno/src/DOM/patching.ts#L530-L739
264// https://github.com/infernojs/inferno/blob/36fd96/packages/inferno/src/DOM/patching.ts#L530-L739
264//
265//
265−// When entering this function, the parent must be on top of the stack:
266+// When entering this function, the parent must be on top of the change list
267+// stack:
266//
268//
267// [... parent]
269// [... parent]
268//
270//
269−// Upon exiting, the stack is in the same state.
271+// Upon exiting, the change list stack is in the same state.
270fn diff_keyed_children(
272fn diff_keyed_children(
271 cached_set: &CachedSet,
273 cached_set: &CachedSet,
272 change_list: &mut ChangeListBuilder,
274 change_list: &mut ChangeListBuilder,
@@ -369,11 +371,11 @@ enum KeyedPrefixResult {
369// Diff the prefix of children in `new` and `old` that share the same keys in
371// Diff the prefix of children in `new` and `old` that share the same keys in
370// the same order.
372// the same order.
371//
373//
372−// Upon entry of this function, the stack must be:
374+// Upon entry of this function, the change list stack must be:
373//
375//
374// [... parent]
376// [... parent]
375//
377//
376−// Upon exit, the stack is the same.
378+// Upon exit, the change list stack is the same.
377fn diff_keyed_prefix(
379fn diff_keyed_prefix(
378 cached_set: &CachedSet,
380 cached_set: &CachedSet,
379 change_list: &mut ChangeListBuilder,
381 change_list: &mut ChangeListBuilder,
@@ -402,7 +404,7 @@ fn diff_keyed_prefix(
402 diff(cached_set, change_list, registry, old, new, cached_roots);
404 diff(cached_set, change_list, registry, old, new, cached_roots);
403 shared_prefix_count += 1;
405 shared_prefix_count += 1;
404
406
405− // At the end of the loop, the stack looks like
407+ // At the end of the loop, the change list stack looks like
406 //
408 //
407 // [... parent child_we_just_diffed]
409 // [... parent child_we_just_diffed]
408 debug_assert!(pushed);
410 debug_assert!(pushed);
@@ -453,7 +455,7 @@ fn diff_keyed_prefix(
453// this subsequence will remain in place, minimizing the number of DOM moves we
455// this subsequence will remain in place, minimizing the number of DOM moves we
454// will have to do.
456// will have to do.
455//
457//
456−// Upon entry to this function, the stack must be:
458+// Upon entry to this function, the change list stack must be:
457//
459//
458// [... parent]
460// [... parent]
459//
461//
@@ -571,7 +573,7 @@ fn diff_keyed_middle(
571 }
573 }
572 }
574 }
573
575
574− // Whether we have pushed a child onto the stack or not.
576+ // Whether we have pushed a child onto the change list stack or not.
575 let mut pushed = false;
577 let mut pushed = false;
576
578
577 // Now iterate from the end of the new children back to the beginning,
579 // Now iterate from the end of the new children back to the beginning,
@@ -660,15 +662,15 @@ fn diff_keyed_middle(
660// segment's nodes must _not_ be members of the LIS (those nodes we will diff in
662// segment's nodes must _not_ be members of the LIS (those nodes we will diff in
661// place elsewhere, and we should not move them nor create them afresh).
663// place elsewhere, and we should not move them nor create them afresh).
662//
664//
663−// On entering this function, the stack has the parent and optionally the next
665+// On entering this function, the change list stack has the parent and
664−// sibling after this segment of children:
666+// optionally the next sibling after this segment of children:
665//
667//
666// [... parent next_sibling] if *pushed == true
668// [... parent next_sibling] if *pushed == true
667// [... parent] otherwise
669// [... parent] otherwise
668//
670//
669// After exiting, if any children were moved or created, then `pushed` is set to
671// After exiting, if any children were moved or created, then `pushed` is set to
670−// true and the stack has the first child in this segment on top. Otherwise the
672+// true and the change list stack has the first child in this segment on
671−// stack is left as it was on entering.
673+// top. Otherwise the stack is left as it was on entering.
672//
674//
673// [... parent child] if *pushed == true
675// [... parent child] if *pushed == true
674// [... parent] otherwise
676// [... parent] otherwise
@@ -706,7 +708,7 @@ fn diff_and_move_or_create_segment(
706 );
708 );
707 }
709 }
708
710
709− // At this point the stack can have one of two shapes.
711+ // At this point the change list stack can have one of two shapes.
710 if *pushed {
712 if *pushed {
711 // [... parent next_child new_child]
713 // [... parent next_child new_child]
712 change_list.insert_before();
714 change_list.insert_before();
@@ -720,7 +722,7 @@ fn diff_and_move_or_create_segment(
720 *pushed = true;
722 *pushed = true;
721 }
723 }
722
724
723− // At the end of each loop iteration, the stack looks like:
725+ // At the end of each loop iteration, the change list stack looks like:
724 //
726 //
725 // [... parent new_child]
727 // [... parent new_child]
726 debug_assert!(*pushed);
728 debug_assert!(*pushed);
@@ -729,11 +731,11 @@ fn diff_and_move_or_create_segment(
729
731
730// Diff the suffix of keyed children that share the same keys in the same order.
732// Diff the suffix of keyed children that share the same keys in the same order.
731//
733//
732−// The parent must be on the stack when we enter this function:
734+// The parent must be on the change list stack when we enter this function:
733//
735//
734// [... parent]
736// [... parent]
735//
737//
736−// When this function exits, the stack remains the same.
738+// When this function exits, the change list stack remains the same.
737fn diff_keyed_suffix(
739fn diff_keyed_suffix(
738 cached_set: &CachedSet,
740 cached_set: &CachedSet,
739 change_list: &mut ChangeListBuilder,
741 change_list: &mut ChangeListBuilder,
@@ -771,11 +773,12 @@ fn diff_keyed_suffix(
771
773
772// Diff children that are not keyed.
774// Diff children that are not keyed.
773//
775//
774−// The parent must be on the top of the stack when entering this function:
776+// The parent must be on the top of the change list stack when entering this
777+// function:
775//
778//
776// [... parent]
779// [... parent]
777//
780//
778−// The stack is in the same state when this function returns.
781+// the change list stack is in the same state when this function returns.
779fn diff_non_keyed_children(
782fn diff_non_keyed_children(
780 cached_set: &CachedSet,
783 cached_set: &CachedSet,
781 change_list: &mut ChangeListBuilder,
784 change_list: &mut ChangeListBuilder,
@@ -828,11 +831,11 @@ fn diff_non_keyed_children(
828
831
829// Create the given children and append them to the parent node.
832// Create the given children and append them to the parent node.
830//
833//
831−// The parent node must currently be on top of the stack:
834+// The parent node must currently be on top of the change list stack:
832//
835//
833// [... parent]
836// [... parent]
834//
837//
835−// When this function returns, the stack is in the same state.
838+// When this function returns, the change list stack is in the same state.
836fn create_and_append_children(
839fn create_and_append_children(
837 cached_set: &CachedSet,
840 cached_set: &CachedSet,
838 change_list: &mut ChangeListBuilder,
841 change_list: &mut ChangeListBuilder,
@@ -848,11 +851,11 @@ fn create_and_append_children(
848
851
849// Remove all of a node's children.
852// Remove all of a node's children.
850//
853//
851−// The stack must have this shape upon entry to this function:
854+// The change list stack must have this shape upon entry to this function:
852//
855//
853// [... parent]
856// [... parent]
854//
857//
855−// When this function returns, the stack is in the same state.
858+// When this function returns, the change list stack is in the same state.
856fn remove_all_children(
859fn remove_all_children(
857 change_list: &mut ChangeListBuilder,
860 change_list: &mut ChangeListBuilder,
858 registry: &mut EventsRegistry,
861 registry: &mut EventsRegistry,
@@ -868,11 +871,11 @@ fn remove_all_children(
868
871
869// Remove the current child and all of its following siblings.
872// Remove the current child and all of its following siblings.
870//
873//
871−// The stack must have this shape upon entry to this function:
874+// The change list stack must have this shape upon entry to this function:
872//
875//
873// [... parent child]
876// [... parent child]
874//
877//
875−// After the function returns, the child is no longer on the stack:
878+// After the function returns, the child is no longer on the change list stack:
876//
879//
877// [... parent]
880// [... parent]
878fn remove_self_and_next_siblings(
881fn remove_self_and_next_siblings(
@@ -888,11 +891,11 @@ fn remove_self_and_next_siblings(
888
891
889// Emit instructions to create the given virtual node.
892// Emit instructions to create the given virtual node.
890//
893//
891−// The stack may have any shape upon entering this function:
894+// The change list stack may have any shape upon entering this function:
892//
895//
893// [...]
896// [...]
894//
897//
895−// When this function returns, the new node is on top of the stack:
898+// When this function returns, the new node is on top of the change list stack:
896//
899//
897// [... node]
900// [... node]
898fn create(
901fn create(