@@ -172,7 +172,6 @@ impl ErasedSegment {
172
172
173
173
pub fn get_raw_segments ( & self ) -> Vec < ErasedSegment > {
174
174
self . recursive_crawl_all ( false )
175
- . into_iter ( )
176
175
. filter ( |it| it. segments ( ) . is_empty ( ) )
177
176
. collect ( )
178
177
}
@@ -618,22 +617,26 @@ impl ErasedSegment {
618
617
)
619
618
}
620
619
621
- pub fn recursive_crawl_all ( & self , reverse : bool ) -> Vec < ErasedSegment > {
622
- let mut result = Vec :: with_capacity ( self . segments ( ) . len ( ) + 1 ) ;
620
+ pub fn recursive_crawl_all ( & self , reverse : bool ) -> impl Iterator < Item = ErasedSegment > + ' _ {
621
+ let self_clone = self . clone ( ) ;
623
622
624
623
if reverse {
625
- for seg in self . segments ( ) . iter ( ) . rev ( ) {
626
- result. append ( & mut seg. recursive_crawl_all ( reverse) ) ;
627
- }
628
- result. push ( self . clone ( ) ) ;
624
+ Box :: new (
625
+ self . segments ( )
626
+ . iter ( )
627
+ . rev ( )
628
+ . flat_map ( move |seg| seg. recursive_crawl_all ( reverse) )
629
+ . chain ( std:: iter:: once ( self_clone) ) ,
630
+ ) as Box < dyn Iterator < Item = _ > >
629
631
} else {
630
- result. push ( self . clone ( ) ) ;
631
- for seg in self . segments ( ) {
632
- result. append ( & mut seg. recursive_crawl_all ( reverse) ) ;
633
- }
632
+ Box :: new (
633
+ std:: iter:: once ( self_clone) . chain (
634
+ self . segments ( )
635
+ . iter ( )
636
+ . flat_map ( move |seg| seg. recursive_crawl_all ( reverse) ) ,
637
+ ) ,
638
+ ) as Box < dyn Iterator < Item = _ > >
634
639
}
635
-
636
- result
637
640
}
638
641
639
642
pub fn raw_segments_with_ancestors ( & self ) -> & [ ( ErasedSegment , Vec < PathStep > ) ] {
0 commit comments