on master help sign in
Add comments clarifying logic about change list stack in `diff_non_keyed_children`
fc6a13cNick Fitzgerald
src/diff.rs+16
@@ -793,9 +793,13 @@ fn diff_non_keyed_children(
793
793
794 for (i, (new_child, old_child)) in new.iter().zip(old.iter()).enumerate() {
794 for (i, (new_child, old_child)) in new.iter().zip(old.iter()).enumerate() {
795 if i == 0 {
795 if i == 0 {
796+ // [... parent]
796 change_list.push_first_child();
797 change_list.push_first_child();
798+ // [... parent first_child]
797 } else {
799 } else {
800+ // [... parent prev_sibling]
798 change_list.pop_push_next_sibling();
801 change_list.pop_push_next_sibling();
802+ // [... parent next_sibling]
799 }
803 }
800
804
801 diff(
805 diff(
@@ -808,13 +812,23 @@ fn diff_non_keyed_children(
808 );
812 );
809 }
813 }
810
814
815+ // Note that because `new` and `old` are not empty, the previous loop always
816+ // executes at least once, so the change list stack is now:
817+ //
818+ // [... parent child]
819+
811 match old.len().cmp(&new.len()) {
820 match old.len().cmp(&new.len()) {
812 Ordering::Greater => {
821 Ordering::Greater => {
822+ // [... parent last_shared_child]
813 change_list.pop_push_next_sibling();
823 change_list.pop_push_next_sibling();
824+ // [... parent first_child_to_remove]
814 remove_self_and_next_siblings(change_list, registry, &old[new.len()..]);
825 remove_self_and_next_siblings(change_list, registry, &old[new.len()..]);
826+ // [... parent]
815 }
827 }
816 Ordering::Less => {
828 Ordering::Less => {
829+ // [... parent last_child]
817 change_list.pop();
830 change_list.pop();
831+ // [... parent]
818 create_and_append_children(
832 create_and_append_children(
819 cached_set,
833 cached_set,
820 change_list,
834 change_list,
@@ -824,7 +838,9 @@ fn diff_non_keyed_children(
824 );
838 );
825 }
839 }
826 Ordering::Equal => {
840 Ordering::Equal => {
841+ // [... parent child]
827 change_list.pop();
842 change_list.pop();
843+ // [... parent]
828 }
844 }
829 }
845 }
830}
846}