Skip to content

Commit 973a6bb

Browse files
committed
Review edits.
1 parent fcf7690 commit 973a6bb

File tree

2 files changed

+231
-209
lines changed

2 files changed

+231
-209
lines changed

analyze/analyses/paths/mod.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,22 @@ pub fn paths(items: &mut ir::Items, opts: &opt::Paths) -> Result<Box<traits::Emi
2727

2828
// Initialize the collection of Id values whose retaining paths we will emit.
2929
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)?
3231
.iter()
3332
.map(|id| create_entry(*id, &items, &opts, &mut BTreeSet::new()))
3433
.collect();
3534

36-
let paths = Paths {
37-
opts,
38-
entries,
39-
};
35+
let paths = Paths { opts, entries };
4036

4137
Ok(Box::new(paths) as Box<traits::Emit>)
4238
}
4339

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> {
4746
// Collect Id's if no arguments are given and we are ascending the retaining paths.
4847
let get_functions_default = || -> Vec<ir::Id> {
4948
let mut sorted_items = items
@@ -108,10 +107,13 @@ fn create_entry(
108107
opts: &opt::Paths,
109108
seen: &mut BTreeSet<ir::Id>,
110109
) -> PathsEntry {
110+
// Determine the item's name and size.
111111
let item = &items[id];
112112
let name = item.name().to_string();
113113
let size = item.size();
114114

115+
// Collect the `ir::Id` values of this entry's children, depending on
116+
// whether we are ascending or descending the IR-tree.
115117
let children_ids: Vec<ir::Id> = if opts.descending() {
116118
items
117119
.neighbors(id)
@@ -128,6 +130,8 @@ fn create_entry(
128130
.collect()
129131
};
130132

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.
131135
seen.insert(id);
132136
let children = children_ids
133137
.into_iter()

0 commit comments

Comments
 (0)