File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -256,12 +256,18 @@ class SymbolTree {
256256 }
257257
258258 let object = this . _node ( parent ) . first ;
259+ let index = 0 ;
259260
260261 while ( object ) {
262+ const node = this . _node ( object ) ;
263+ node . setCachedIndex ( parent , index ) ;
264+
261265 if ( filter . call ( thisArg , object ) ) {
262266 array . push ( object ) ;
263267 }
264- object = this . _node ( object ) . next ;
268+
269+ object = node . next ;
270+ ++ index ;
265271 }
266272
267273 return array ;
Original file line number Diff line number Diff line change @@ -961,6 +961,29 @@ test('cached index', function(t) {
961961 t . end ( ) ;
962962} ) ;
963963
964+ test ( 'cached index warmed up by childrenToArray' , function ( t ) {
965+ const tree = new SymbolTree ( ) ;
966+ const a = { } ;
967+ const aa = { } ;
968+ const ab = { } ;
969+ const aba = { } ;
970+ const ac = { } ;
971+ const b = { } ;
972+
973+ tree . insertLast ( aa , a ) ;
974+ tree . insertLast ( ab , a ) ;
975+ tree . insertLast ( aba , ab ) ;
976+ tree . insertLast ( ac , a ) ;
977+ tree . insertAfter ( b , a ) ;
978+
979+ tree . childrenToArray ( a ) ;
980+ t . equal ( 0 , tree . index ( aa ) ) ;
981+ t . equal ( 1 , tree . index ( ab ) ) ;
982+ t . equal ( 2 , tree . index ( ac ) ) ;
983+
984+ t . end ( ) ;
985+ } ) ;
986+
964987test ( 'children count' , function ( t ) {
965988 // no need to test the caching since we already tested for that in childrenCount
966989 const tree = new SymbolTree ( ) ;
You can’t perform that action at this time.
0 commit comments