@@ -51,10 +51,6 @@ pub struct Taffy {
5151 /// the layout algorithms during layout, while exposing the `NodeData.final_layout` when called by external users.
5252 /// This allows us to fix <https://github.com/DioxusLabs/taffy/issues/501> without breaking backwards compatibility
5353 pub ( crate ) is_layouting : bool ,
54-
55- /// Used to cache the resolved children of a node (taking into account `Display::contents`) during layout
56- /// so that repeated calls to the children method don't need to re-resolve the list.
57- node_children_cache : RefCell < ( NodeId , Vec < NodeId > ) > ,
5854}
5955
6056impl Default for Taffy {
@@ -98,13 +94,13 @@ impl LayoutTree for Taffy {
9894
9995 #[ inline( always) ]
10096 fn children ( & self , node : NodeId ) -> Self :: ChildIter < ' _ > {
101- let mut cache = self . node_children_cache . borrow_mut ( ) ;
102- if cache. 0 != node {
103- cache . 1 . clear ( ) ;
104- cache . 0 = node;
105- find_children_recursive ( & mut cache. 1 , self , node ) ;
97+ let mut cache = self . nodes [ node . into ( ) ] . children_cache . borrow_mut ( ) ;
98+ if cache. is_none ( ) {
99+ let mut children = Vec :: new ( ) ;
100+ find_children_recursive ( & mut children , self , node) ;
101+ * cache = Some ( children ) ;
106102 }
107- RefCellVecIter { children : RefMut :: map ( cache, |c| & mut c . 1 ) , index : 0 }
103+ RefCellVecIter { children : RefMut :: map ( cache, |c| c . as_mut ( ) . unwrap ( ) ) , index : 0 }
108104 }
109105
110106 #[ inline( always) ]
@@ -171,15 +167,17 @@ impl LayoutTree for Taffy {
171167 sizing_mode : SizingMode ,
172168 vertical_margins_are_collapsible : Line < bool > ,
173169 ) -> SizeBaselinesAndMargins {
174- perform_node_layout (
170+ let result = perform_node_layout (
175171 self ,
176172 node,
177173 known_dimensions,
178174 parent_size,
179175 available_space,
180176 sizing_mode,
181177 vertical_margins_are_collapsible,
182- )
178+ ) ;
179+ * self . nodes [ node. into ( ) ] . children_cache . borrow_mut ( ) = None ;
180+ result
183181 }
184182}
185183
@@ -205,7 +203,6 @@ impl Taffy {
205203 measure_funcs : SparseSecondaryMap :: with_capacity ( capacity) ,
206204 config : TaffyConfig :: default ( ) ,
207205 is_layouting : false ,
208- node_children_cache : RefCell :: new ( ( NodeId :: new ( 0 ) , Vec :: new ( ) ) ) ,
209206 }
210207 }
211208
0 commit comments