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 {
256
256
}
257
257
258
258
let object = this . _node ( parent ) . first ;
259
+ let index = 0 ;
259
260
260
261
while ( object ) {
262
+ const node = this . _node ( object ) ;
263
+ node . setCachedIndex ( parent , index ) ;
264
+
261
265
if ( filter . call ( thisArg , object ) ) {
262
266
array . push ( object ) ;
263
267
}
264
- object = this . _node ( object ) . next ;
268
+
269
+ object = node . next ;
270
+ ++ index ;
265
271
}
266
272
267
273
return array ;
Original file line number Diff line number Diff line change @@ -961,6 +961,29 @@ test('cached index', function(t) {
961
961
t . end ( ) ;
962
962
} ) ;
963
963
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
+
964
987
test ( 'children count' , function ( t ) {
965
988
// no need to test the caching since we already tested for that in childrenCount
966
989
const tree = new SymbolTree ( ) ;
You can’t perform that action at this time.
0 commit comments