@@ -380,8 +380,6 @@ impl DiffState<'_, '_, '_, '_> {
380380 lis_sequence. remove ( 0 ) ;
381381 }
382382
383- let mut mounted_new = Vec :: new ( ) ;
384-
385383 // Every shared child not in the stable LIS will move, so its committed
386384 // position is stale for the rest of this reorder. Mark them all up front
387385 // (O(1) each) so placement scans never anchor on a node that is mid-move,
@@ -416,7 +414,6 @@ impl DiffState<'_, '_, '_, '_> {
416414 new_mounts[ * idx] = Some ( mount) ;
417415 self . dom
418416 . set_mounted_fragment_child ( new_children, new_offset + * idx, mount) ;
419- mounted_new. push ( MountedSibling { index : * idx, mount } ) ;
420417 }
421418
422419 let last = * lis_sequence. first ( ) . unwrap ( ) ;
@@ -433,7 +430,6 @@ impl DiffState<'_, '_, '_, '_> {
433430 & mut * new_mounts,
434431 new_children,
435432 new_offset,
436- & mut mounted_new,
437433 ) ;
438434 }
439435
@@ -452,7 +448,6 @@ impl DiffState<'_, '_, '_, '_> {
452448 new_mounts,
453449 new_children,
454450 new_offset,
455- & mut mounted_new,
456451 ) ;
457452 }
458453 }
@@ -471,7 +466,6 @@ impl DiffState<'_, '_, '_, '_> {
471466 & mut * new_mounts,
472467 new_children,
473468 new_offset,
474- & mut mounted_new,
475469 ) ;
476470 }
477471
@@ -534,7 +528,6 @@ impl DiffState<'_, '_, '_, '_> {
534528 new_mounts : & mut [ Option < MountId > ] ,
535529 new_children : FragmentMountWriter ,
536530 new_offset : usize ,
537- mounted_new : & mut Vec < MountedSibling > ,
538531 ) {
539532 let context = self . context ( ) ;
540533 let sibling_mount = new_mounts[ sibling_idx] . expect ( "sibling" ) ;
@@ -549,7 +542,7 @@ impl DiffState<'_, '_, '_, '_> {
549542 crate :: MountedVNode :: new ( & new[ sibling_idx] , sibling_mount) ,
550543 self . dom ,
551544 )
552- . or_else ( || insertion_site_in_new_order ( edge, new, mounted_new , sibling_idx, self . dom ) )
545+ . or_else ( || insertion_site_in_new_order ( edge, new, new_mounts , sibling_idx, self . dom ) )
553546 . unwrap_or_else ( || {
554547 insertion_site_at (
555548 edge,
@@ -577,7 +570,6 @@ impl DiffState<'_, '_, '_, '_> {
577570 new_mounts,
578571 new_children,
579572 new_offset,
580- mounted_new,
581573 & mut replaced_nodes,
582574 )
583575 } ) ;
@@ -593,7 +585,6 @@ impl DiffState<'_, '_, '_, '_> {
593585 new_mounts,
594586 new_children,
595587 new_offset,
596- mounted_new,
597588 & mut replaced_nodes,
598589 ) ;
599590 }
@@ -617,7 +608,6 @@ impl DiffState<'_, '_, '_, '_> {
617608 new_mounts : & mut [ Option < MountId > ] ,
618609 new_children : FragmentMountWriter ,
619610 new_offset : usize ,
620- mounted_new : & mut Vec < MountedSibling > ,
621611 replaced_nodes : & mut Vec < ( & ' a VNode , MountId ) > ,
622612 ) -> usize {
623613 let range_start = range. start ;
@@ -658,10 +648,6 @@ impl DiffState<'_, '_, '_, '_> {
658648 new_mounts[ new_index] = Some ( mount) ;
659649 self . dom
660650 . set_mounted_fragment_child ( new_children, new_offset + new_index, mount) ;
661- mounted_new. push ( MountedSibling {
662- index : new_index,
663- mount,
664- } ) ;
665651 nodes += created_nodes;
666652 }
667653 nodes
@@ -732,44 +718,30 @@ impl DiffState<'_, '_, '_, '_> {
732718 }
733719}
734720
735- #[ derive( Clone , Copy ) ]
736- struct MountedSibling {
737- index : usize ,
738- mount : MountId ,
739- }
740-
741721/// Prefer anchors already materialized in the new sibling order.
742722///
743- /// Invariant: every entry in `mounted_new ` owns a live mount in ` new` order. Pending new siblings are
744- /// not representable in this slice and therefore cannot be used as anchors.
723+ /// Invariant: every `Some` entry in `new_mounts ` owns a materialized sibling in new order. Pending
724+ /// new siblings are `None` and therefore cannot be used as anchors.
745725fn insertion_site_in_new_order (
746726 edge : ElementEdge ,
747727 new : & [ VNode ] ,
748- mounted_new : & [ MountedSibling ] ,
728+ new_mounts : & [ Option < MountId > ] ,
749729 sibling_idx : usize ,
750730 dom : & VirtualDom ,
751731) -> Option < InsertionSite > {
752732 match edge {
753- ElementEdge :: First => mounted_new
754- . iter ( )
755- . filter ( |sibling| sibling. index >= sibling_idx)
756- . filter_map ( |sibling| {
757- new[ sibling. index ]
758- . find_first_element ( sibling. mount , dom)
759- . map ( |id| ( sibling. index , id) )
760- } )
761- . min_by_key ( |( index, _) | * index)
762- . map ( |( _, id) | InsertionSite :: before ( id) ) ,
763- ElementEdge :: Last => mounted_new
764- . iter ( )
765- . filter ( |sibling| sibling. index <= sibling_idx)
766- . filter_map ( |sibling| {
767- new[ sibling. index ]
768- . find_last_element ( sibling. mount , dom)
769- . map ( |id| ( sibling. index , id) )
770- } )
771- . max_by_key ( |( index, _) | * index)
772- . map ( |( _, id) | InsertionSite :: after ( id) ) ,
733+ ElementEdge :: First => ( sibling_idx..new. len ( ) ) . find_map ( |index| {
734+ let mount = new_mounts[ index] ?;
735+ new[ index]
736+ . find_first_element ( mount, dom)
737+ . map ( InsertionSite :: before)
738+ } ) ,
739+ ElementEdge :: Last => ( 0 ..=sibling_idx) . rev ( ) . find_map ( |index| {
740+ let mount = new_mounts[ index] ?;
741+ new[ index]
742+ . find_last_element ( mount, dom)
743+ . map ( InsertionSite :: after)
744+ } ) ,
773745 }
774746}
775747
0 commit comments