fn diff_keyed_children(&mut self, old: &'bump [VNode<'bump>], new: &'bump [VNode<'bump>]) {
        if cfg!(debug_assertions) {
            let mut keys = fxhash::FxHashSet::default();
            let mut assert_unique_keys = |children: &'bump [VNode<'bump>]| {
                keys.clear();
                for child in children {
                    let key = child.key();
                    debug_assert!(
                        key.is_some(),
                        "if any sibling is keyed, all siblings must be keyed"
                    );
                    keys.insert(key);
                }
                debug_assert_eq!(
                    children.len(),
                    keys.len(),
                    "keyed siblings must each have a unique key"
                );
            };
            assert_unique_keys(old);
            assert_unique_keys(new);
        }

        // First up, we diff all the nodes with the same key at the beginning of the
        // children.
        //
        // `shared_prefix_count` is the count of how many nodes at the start of
        // `new` and `old` share the same keys.
        let (left_offset, right_offset) = match self.diff_keyed_ends(old, new) {
            Some(count) => count,
            None => return,
        };

        // Ok, we now hopefully have a smaller range of children in the middle
        // within which to re-order nodes with the same keys, remove old nodes with
        // now-unused keys, and create new nodes with fresh keys.

        let old_middle = &old[left_offset..(old.len() - right_offset)];
        let new_middle = &new[left_offset..(new.len() - right_offset)];

        debug_assert!(
            !((old_middle.len() == new_middle.len()) && old_middle.is_empty()),
            "keyed children must have the same number of children"
        );
        if new_middle.is_empty() {
            // remove the old elements
            self.remove_nodes(old_middle, true);
        } else if old_middle.is_empty() {
            // there were no old elements, so just create the new elements
            // we need to find the right "foothold" though - we shouldn't use the "append" at all
            if left_offset == 0 {
                // insert at the beginning of the old list
                let foothold = &old[old.len() - right_offset];
                self.stack.create_children(
                    new_middle,
                    MountType::InsertBefore {
                        other_node: foothold,
                    },
                );
            } else if right_offset == 0 {
                // insert at the end  the old list
                let foothold = old.last().unwrap();
                self.stack.create_children(
                    new_middle,
                    MountType::InsertAfter {
                        other_node: foothold,
                    },
                );
            } else {
                // inserting in the middle
                let foothold = &old[left_offset - 1];
                self.stack.create_children(
                    new_middle,
                    MountType::InsertAfter {
                        other_node: foothold,
                    },
                );
            }
        } else {
            self.diff_keyed_middle(old_middle, new_middle);
        }
    }
// Diffing "keyed" children.
//
// With keyed children, we care about whether we delete, move, or create nodes
// versus mutate existing nodes in place. Presumably there is some sort of CSS
// transition animation that makes the virtual DOM diffing algorithm
// observable. By specifying keys for nodes, we know which virtual DOM nodes
// must reuse (or not reuse) the same physical DOM nodes.
//
// This is loosely based on Inferno's keyed patching implementation. However, we
// have to modify the algorithm since we are compiling the diff down into change
// list instructions that will be executed later, rather than applying the
// changes to the DOM directly as we compare virtual DOMs.
//
// https://github.com/infernojs/inferno/blob/36fd96/packages/inferno/src/DOM/patching.ts#L530-L739
//
// The stack is empty upon entry.
Diffing "keyed" children.
With keyed children, we care about whether we delete, move, or create nodes
versus mutate existing nodes in place. Presumably there is some sort of CSS
transition animation that makes the virtual DOM diffing algorithm
observable. By specifying keys for nodes, we know which virtual DOM nodes
must reuse (or not reuse) the same physical DOM nodes.

This is loosely based on Inferno's keyed patching implementation. However, we
have to modify the algorithm since we are compiling the diff down into change
list instructions that will be executed later, rather than applying the
changes to the DOM directly as we compare virtual DOMs.



The stack is empty upon entry.
Diffing " keyed " children . With keyed children we care about whether we delete move or create nodes versus mutate existing nodes in place . Presumably there is some sort of CSS transition animation that makes the virtual DOM diffing algorithm observable . By specifying keys for nodes we know which virtual DOM nodes must reuse ( or not reuse ) the same physical DOM nodes . This is loosely based on Inferno ' s keyed patching implementation . However we have to modify the algorithm since we are compiling the diff down into change list instructions that will be executed later rather than applying the changes to the DOM directly as we compare virtual DOMs . The stack is empty upon entry .
fn diff_keyed_children(&mut self, old: &'bump [VNode<'bump>], new: &'bump [VNode<'bump>]) {
        if cfg!(debug_assertions) {
            let mut keys = fxhash::FxHashSet::default();
            let mut assert_unique_keys = |children: &'bump [VNode<'bump>]| {
                keys.clear();
                for child in children {
                    let key = child.key();
                    debug_assert!(
                        key.is_some(),
                        "if any sibling is keyed, all siblings must be keyed"
                    );
                    keys.insert(key);
                }
                debug_assert_eq!(
                    children.len(),
                    keys.len(),
                    "keyed siblings must each have a unique key"
                );
            };
            assert_unique_keys(old);
            assert_unique_keys(new);
        }
        // First up, we diff all the nodes with the same key at the beginning of the
        // children.
        //
        // `shared_prefix_count` is the count of how many nodes at the start of
        // `new` and `old` share the same keys.
        let (left_offset, right_offset) = match self.diff_keyed_ends(old, new) {
            Some(count) => count,
            None => return,
        };
        // Ok, we now hopefully have a smaller range of children in the middle
        // within which to re-order nodes with the same keys, remove old nodes with
        // now-unused keys, and create new nodes with fresh keys.
        let old_middle = &old[left_offset..(old.len() - right_offset)];
        let new_middle = &new[left_offset..(new.len() - right_offset)];
        debug_assert!(
            !((old_middle.len() == new_middle.len()) && old_middle.is_empty()),
            "keyed children must have the same number of children"
        );
        if new_middle.is_empty() {
            // remove the old elements
            self.remove_nodes(old_middle, true);
        } else if old_middle.is_empty() {
            // there were no old elements, so just create the new elements
            // we need to find the right "foothold" though - we shouldn't use the "append" at all
            if left_offset == 0 {
                // insert at the beginning of the old list
                let foothold = &old[old.len() - right_offset];
                self.stack.create_children(
                    new_middle,
                    MountType::InsertBefore {
                        other_node: foothold,
                    },
                );
            } else if right_offset == 0 {
                // insert at the end  the old list
                let foothold = old.last().unwrap();
                self.stack.create_children(
                    new_middle,
                    MountType::InsertAfter {
                        other_node: foothold,
                    },
                );
            } else {
                // inserting in the middle
                let foothold = &old[left_offset - 1];
                self.stack.create_children(
                    new_middle,
                    MountType::InsertAfter {
                        other_node: foothold,
                    },
                );
            }
        } else {
            self.diff_keyed_middle(old_middle, new_middle);
        }
    }
fn diff_keyed_children ( & mut self , old : & ' bump [ VNode < ' bump > ] , new : & ' bump [ VNode < ' bump > ] ) { if cfg ! ( debug_assertions ) { let mut keys = fxhash :: FxHashSet :: default ( ) ; let mut assert_unique_keys = | children : & ' bump [ VNode < ' bump > ] | { keys . clear ( ) ; for child in children { let key = child . key ( ) ; debug_assert ! ( key is_some ( ) " " ) ; keys . insert ( key ) ; } debug_assert_eq ! ( children len ( ) keys len ( ) " " ) ; } ; assert_unique_keys ( old ) ; assert_unique_keys ( new ) ; } // First up, we diff all the nodes with the same key at the beginning of the // children. // // `shared_prefix_count` is the count of how many nodes at the start of // `new` and `old` share the same keys. let ( left_offset , right_offset ) = match self . diff_keyed_ends ( old , new ) { Some ( count ) => count , None => return , } ; // Ok, we now hopefully have a smaller range of children in the middle // within which to re-order nodes with the same keys, remove old nodes with // now-unused keys, and create new nodes with fresh keys. let old_middle = & old [ left_offset .. ( old . len ( ) - right_offset ) ] ; let new_middle = & new [ left_offset .. ( new . len ( ) - right_offset ) ] ; debug_assert ! ( ( ( old_middle len ( ) new_middle len ( ) ) old_middle is_empty ( ) ) " " ) ; if new_middle . is_empty ( ) { // remove the old elements self . remove_nodes ( old_middle , true ) ; } else if old_middle . is_empty ( ) { // there were no old elements, so just create the new elements // we need to find the right "foothold" though - we shouldn't use the "append" at all if left_offset == 0 { // insert at the beginning of the old list let foothold = & old [ old . len ( ) - right_offset ] ; self . stack . create_children ( new_middle , MountType :: InsertBefore { other_node : foothold , } , ) ; } else if right_offset == 0 { // insert at the end  the old list let foothold = old . last ( ) . unwrap ( ) ; self . stack . create_children ( new_middle , MountType :: InsertAfter { other_node : foothold , } , ) ; } else { // inserting in the middle let foothold = & old [ left_offset - 1 ] ; self . stack . create_children ( new_middle , MountType :: InsertAfter { other_node : foothold , } , ) ; } } else { self . diff_keyed_middle ( old_middle , new_middle ) ; } }
Diffing "keyed" children.
Diffing " keyed " children .
&mut self
old
&'bump [VNode<'bump>]
new
&'bump [VNode<'bump>]