Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Optimization] - Custom visitor, index tree, scoped thread #86

Merged
merged 6 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ clap_complete = "4.1.1"
crossbeam = "0.8.2"
filesize = "0.2.0"
ignore = "0.4.2"
indextree = "4.6.0"
lscolors = { version = "0.13.0", features = ["ansi_term"] }
num_cpus = "1.15.0"
once_cell = "1.17.0"
Expand Down
48 changes: 27 additions & 21 deletions src/render/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,45 +141,34 @@ impl Context {
// user arguments.
let mut args = vec![OsString::from("--")];

// Used to pick either from config or user args.
let mut pick_args_from = |id: &str, matches: &ArgMatches| {
if let Ok(Some(raw)) = matches.try_get_raw(id) {
let kebap = id.replace("_", "-");

let raw_args = raw
.map(OsStr::to_owned)
.map(|s| vec![OsString::from(format!("--{}", kebap)), s])
.filter(|pair| pair[1] != "false")
.flatten()
.filter(|s| s != "true")
.collect::<Vec<OsString>>();

args.extend(raw_args);
}
};

let mut ids = user_args.ids().map(Id::as_str).collect::<Vec<&str>>();

ids.extend(config_args.ids().map(Id::as_str).collect::<Vec<&str>>());

ids = crate::utils::uniq(ids);

for id in ids {
// Don't look at me... my shame..
if id == "Context" {
continue;
} else if id == "dir" {
if let Ok(Some(raw)) = user_args.try_get_raw(id) {
let raw_args = raw.map(OsStr::to_owned).collect::<Vec<OsString>>();

args.extend(raw_args);
continue;
}
}

if let Some(user_arg) = user_args.value_source(id) {
match user_arg {
// prioritize the user arg if user provided a command line argument
ValueSource::CommandLine => pick_args_from(id, &user_args),
ValueSource::CommandLine => Self::pick_args_from(id, &user_args, &mut args),

// otherwise prioritize argument from the config
_ => pick_args_from(id, &config_args),
_ => Self::pick_args_from(id, &config_args, &mut args),
}
} else {
pick_args_from(id, &config_args)
Self::pick_args_from(id, &config_args, &mut args)
}
}

Expand Down Expand Up @@ -241,6 +230,23 @@ impl Context {

builder.build()
}

/// Used to pick either from config or user args when constructing [Context].
fn pick_args_from(id: &str, matches: &ArgMatches, args: &mut Vec<OsString>) {
if let Ok(Some(raw)) = matches.try_get_raw(id) {
let kebap = id.replace("_", "-");

let raw_args = raw
.map(OsStr::to_owned)
.map(|s| vec![OsString::from(format!("--{}", kebap)), s])
.filter(|pair| pair[1] != "false")
.flatten()
.filter(|s| s != "true")
.collect::<Vec<OsString>>();

args.extend(raw_args);
}
}
}

#[derive(Debug)]
Expand Down
8 changes: 4 additions & 4 deletions src/render/disk_usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub enum SiPrefix {
}

/// Represents either logical or physical size and handles presentation.
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct FileSize {
pub bytes: u64,
#[allow(dead_code)]
Expand Down Expand Up @@ -92,9 +92,9 @@ impl FileSize {
}
}

impl AddAssign<&Self> for FileSize {
fn add_assign(&mut self, rhs: &Self) {
self.bytes += rhs.bytes;
impl AddAssign<u64> for FileSize {
fn add_assign(&mut self, rhs: u64) {
self.bytes += rhs;
}
}

Expand Down
Loading