Skip to content

Commit 67d3079

Browse files
committed
refactor: move HDD detection logic to app.rs
it would cost less binary size
1 parent db11ae5 commit 67d3079

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

src/app.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ use crate::{
1212
visualizer::{BarAlignment, Direction, Visualizer},
1313
};
1414
use clap::Parser;
15+
use hdd::any_path_is_in_hdd;
1516
use pipe_trait::Pipe;
1617
use std::{io::stdin, time::Duration};
18+
use sysinfo::Disks;
1719

1820
#[cfg(unix)]
1921
use crate::{
@@ -44,6 +46,18 @@ impl App {
4446
//
4547
// The other operations which are invoked frequently should not utilize dynamic dispatch.
4648

49+
{
50+
// If one of the files is on HDD, set thread number to 1
51+
let disks = Disks::new_with_refreshed_list();
52+
if any_path_is_in_hdd::<hdd::RealApi>(&self.args.files, &disks) {
53+
eprintln!("warning: HDD detected, the thread limit will be set to 1");
54+
rayon::ThreadPoolBuilder::new()
55+
.num_threads(1)
56+
.build_global()
57+
.unwrap_or_else(|_| eprintln!("warning: Failed to set thread limit to 1"));
58+
}
59+
}
60+
4761
let column_width_distribution = self.args.column_width_distribution();
4862

4963
if self.args.json_input {
@@ -202,3 +216,6 @@ impl App {
202216
}
203217
}
204218
}
219+
220+
mod hdd;
221+
mod mount_point;
File renamed without changes.
File renamed without changes.

src/app/sub.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
mod hdd;
2-
mod mount_point;
3-
41
use crate::{
52
args::Fraction,
63
data_tree::{DataTree, DataTreeReflection},
@@ -14,10 +11,8 @@ use crate::{
1411
status_board::GLOBAL_STATUS_BOARD,
1512
visualizer::{BarAlignment, ColumnWidthDistribution, Direction, Visualizer},
1613
};
17-
use hdd::any_path_is_in_hdd;
1814
use serde::Serialize;
1915
use std::{io::stdout, iter::once, num::NonZeroUsize, path::PathBuf};
20-
use sysinfo::Disks;
2116

2217
/// The sub program of the main application.
2318
pub struct Sub<Size, SizeGetter, Report>
@@ -74,17 +69,6 @@ where
7469
no_sort,
7570
} = self;
7671

77-
// If one of the files is on HDD, set thread number to 1
78-
let disks = Disks::new_with_refreshed_list();
79-
80-
if any_path_is_in_hdd::<hdd::RealApi>(&files, &disks) {
81-
eprintln!("warning: HDD detected, the thread limit will be set to 1");
82-
rayon::ThreadPoolBuilder::new()
83-
.num_threads(1)
84-
.build_global()
85-
.unwrap_or_else(|_| eprintln!("warning: Failed to set thread limit to 1"));
86-
}
87-
8872
let mut iter = files
8973
.into_iter()
9074
.map(|root| -> DataTree<OsStringDisplay, Size> {

0 commit comments

Comments
 (0)