Skip to content

Commit 2ff8bf3

Browse files
committed
feat(api)!: remove depth from DataTree::dir
1 parent cde72da commit 2ff8bf3

7 files changed

Lines changed: 18 additions & 12 deletions

File tree

src/app/sub.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ where
101101
OsStringDisplay::os_string_from("(total)"),
102102
Size::default(),
103103
children,
104-
max_depth.get(),
105104
)
106105
};
107106

src/data_tree/constructors.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ use crate::size;
33

44
impl<Name, Size: size::Size> DataTree<Name, Size> {
55
/// Create a tree representation of a directory.
6-
pub fn dir(name: Name, inode_size: Size, children: Vec<Self>, depth: u64) -> Self {
6+
pub fn dir(name: Name, inode_size: Size, children: Vec<Self>) -> Self {
77
let size = inode_size + children.iter().map(DataTree::size).sum();
8-
let children = if depth > 0 { children } else { Vec::new() };
98
DataTree {
109
name,
1110
size,
@@ -27,6 +26,11 @@ impl<Name, Size: size::Size> DataTree<Name, Size> {
2726
where
2827
Size: Copy,
2928
{
30-
move |name, children| DataTree::dir(name, inode_size, children, 1)
29+
move |name, children| DataTree::dir(name, inode_size, children)
30+
}
31+
32+
/// Remove the children. Free memory usage.
33+
pub(crate) fn drop_children(&mut self) {
34+
self.children = Vec::new();
3135
}
3236
}

src/data_tree/retain/test.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ type SampleData = Bytes;
77
type SampleTree = DataTree<SampleName, SampleData>;
88

99
fn dir<const INODE_SIZE: u64>(name: &'static str, children: Vec<SampleTree>) -> SampleTree {
10-
SampleTree::dir(name.to_string(), INODE_SIZE.into(), children, 10)
10+
SampleTree::dir(name.to_string(), INODE_SIZE.into(), children)
1111
}
1212

1313
fn file(name: &'static str, size: u64) -> SampleTree {
@@ -23,7 +23,6 @@ fn culled_dir<const INODE_SIZE: u64>(
2323
name.to_string(),
2424
(INODE_SIZE + culled_size).into(),
2525
children,
26-
10,
2726
)
2827
}
2928

src/tree_builder.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,13 @@ where
5959
max_depth,
6060
})
6161
.map(Self::from)
62-
.collect();
62+
.collect(); // TODO: this collect can be called into different types depending on whether `max_depth` is 0
6363

64-
DataTree::dir(name, size, children, max_depth)
64+
let mut tree = DataTree::dir(name, size, children);
65+
if max_depth == 0 {
66+
// TODO: replace this with a more memory efficient method that doesn't require constructing `children` in the first place
67+
tree.drop_children();
68+
}
69+
tree
6570
}
6671
}

tests/json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type SampleTree = DataTree<SampleName, SampleData>;
3030

3131
fn sample_tree() -> SampleTree {
3232
let dir = |name: &'static str, children: Vec<SampleTree>| {
33-
SampleTree::dir(name.to_string(), 1024.into(), children, 10)
33+
SampleTree::dir(name.to_string(), 1024.into(), children)
3434
};
3535
let file =
3636
|name: &'static str, size: u64| SampleTree::file(name.to_string(), Bytes::from(size));

tests/usual_cli.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,6 @@ fn multiple_names() {
623623
OsStringDisplay::os_string_from("(total)"),
624624
0.into(),
625625
children.collect(),
626-
10,
627626
)
628627
})
629628
.into_par_sorted(|left, right| left.size().cmp(&right.size()).reverse());

tests/visualizer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ fn nested_tree<Size: size::Size>(
403403
) -> DataTree<&'static str, Size> {
404404
if let Some((head, tail)) = dir_names.split_first() {
405405
let child = nested_tree(tail, size_per_dir, file_name, file_size);
406-
DataTree::dir(*head, size_per_dir, vec![child], 10)
406+
DataTree::dir(*head, size_per_dir, vec![child])
407407
} else {
408408
DataTree::file(file_name, file_size)
409409
}
@@ -649,7 +649,7 @@ fn empty_dir<Size>(inode_size: Size) -> DataTree<&'static str, Size>
649649
where
650650
Size: size::Size + Ord + From<u64> + Send,
651651
{
652-
DataTree::dir("empty directory", inode_size, Vec::new(), 10).into_par_sorted(order_tree)
652+
DataTree::dir("empty directory", inode_size, Vec::new()).into_par_sorted(order_tree)
653653
}
654654

655655
test_case! {

0 commit comments

Comments
 (0)