@@ -76,12 +76,15 @@ impl<V: VTable> Array<V> {
7676 let len = V :: len ( & data) ;
7777 let dtype = V :: dtype ( & data) . clone ( ) ;
7878 let stats = data. array_stats ( ) . clone ( ) ;
79+ let child_slots = ( 0 ..V :: nchildren ( & data) )
80+ . map ( |i| Some ( V :: child ( & data, i) ) )
81+ . collect ( ) ;
7982 Self {
8083 vtable,
8184 len,
8285 dtype,
8386 data,
84- child_slots : Vec :: new ( ) ,
87+ child_slots,
8588 stats,
8689 }
8790 }
@@ -372,28 +375,31 @@ impl<V: VTable> ArrayEq for Array<V> {
372375
373376impl < V : VTable > ArrayVisitor for Array < V > {
374377 fn children ( & self ) -> Vec < ArrayRef > {
375- ( 0 ..V :: nchildren ( & self . data ) )
376- . map ( |i| V :: child ( & self . data , i) )
377- . collect ( )
378+ self . child_slots . iter ( ) . filter_map ( |s| s. clone ( ) ) . collect ( )
378379 }
379380
380381 fn nchildren ( & self ) -> usize {
381- V :: nchildren ( & self . data )
382+ self . child_slots . iter ( ) . filter ( |s| s . is_some ( ) ) . count ( )
382383 }
383384
384385 fn nth_child ( & self , idx : usize ) -> Option < ArrayRef > {
385- ( idx < V :: nchildren ( & self . data ) ) . then ( || V :: child ( & self . data , idx ) )
386+ self . child_slots . get ( idx ) . and_then ( |s| s . clone ( ) )
386387 }
387388
388389 fn children_names ( & self ) -> Vec < String > {
389- ( 0 ..V :: nchildren ( & self . data ) )
390+ ( 0 ..self . child_slots . len ( ) )
391+ . filter ( |i| self . child_slots [ * i] . is_some ( ) )
390392 . map ( |i| V :: child_name ( & self . data , i) )
391393 . collect ( )
392394 }
393395
394396 fn named_children ( & self ) -> Vec < ( String , ArrayRef ) > {
395- ( 0 ..V :: nchildren ( & self . data ) )
396- . map ( |i| ( V :: child_name ( & self . data , i) , V :: child ( & self . data , i) ) )
397+ ( 0 ..self . child_slots . len ( ) )
398+ . filter_map ( |i| {
399+ self . child_slots [ i]
400+ . clone ( )
401+ . map ( |child| ( V :: child_name ( & self . data , i) , child) )
402+ } )
397403 . collect ( )
398404 }
399405
0 commit comments