@@ -27,23 +27,22 @@ pub fn paths(items: &mut ir::Items, opts: &opt::Paths) -> Result<Box<traits::Emi
27
27
28
28
// Initialize the collection of Id values whose retaining paths we will emit.
29
29
let opts = opts. clone ( ) ;
30
- let starting_positions = get_items ( & items, & opts) ?;
31
- let entries = starting_positions
30
+ let entries = get_starting_positions ( & items, & opts) ?
32
31
. iter ( )
33
32
. map ( |id| create_entry ( * id, & items, & opts, & mut BTreeSet :: new ( ) ) )
34
33
. collect ( ) ;
35
34
36
- let paths = Paths {
37
- opts,
38
- entries,
39
- } ;
35
+ let paths = Paths { opts, entries } ;
40
36
41
37
Ok ( Box :: new ( paths) as Box < traits:: Emit > )
42
38
}
43
39
44
- /// This helper function is used to collect ir::Id values for the `items` member
45
- /// of the `Paths` object, based on the given options.
46
- pub fn get_items ( items : & ir:: Items , opts : & opt:: Paths ) -> Result < Vec < ir:: Id > , traits:: Error > {
40
+ /// This helper function is used to collect the `ir::Id` values for the top-most
41
+ /// path entries for the `Paths` object, based on the given options.
42
+ fn get_starting_positions (
43
+ items : & ir:: Items ,
44
+ opts : & opt:: Paths ,
45
+ ) -> Result < Vec < ir:: Id > , traits:: Error > {
47
46
// Collect Id's if no arguments are given and we are ascending the retaining paths.
48
47
let get_functions_default = || -> Vec < ir:: Id > {
49
48
let mut sorted_items = items
@@ -108,10 +107,13 @@ fn create_entry(
108
107
opts : & opt:: Paths ,
109
108
seen : & mut BTreeSet < ir:: Id > ,
110
109
) -> PathsEntry {
110
+ // Determine the item's name and size.
111
111
let item = & items[ id] ;
112
112
let name = item. name ( ) . to_string ( ) ;
113
113
let size = item. size ( ) ;
114
114
115
+ // Collect the `ir::Id` values of this entry's children, depending on
116
+ // whether we are ascending or descending the IR-tree.
115
117
let children_ids: Vec < ir:: Id > = if opts. descending ( ) {
116
118
items
117
119
. neighbors ( id)
@@ -128,6 +130,8 @@ fn create_entry(
128
130
. collect ( )
129
131
} ;
130
132
133
+ // Temporarily add the current item to the set of discovered nodes, and
134
+ // create an entry for each child. Collect these into a `children` vector.
131
135
seen. insert ( id) ;
132
136
let children = children_ids
133
137
. into_iter ( )
0 commit comments