Skip to content

Commit

Permalink
Merge pull request #86 from solidiquis/optimization/arena-tree
Browse files Browse the repository at this point in the history
[Optimization] - Custom visitor, index tree, scoped thread
  • Loading branch information
solidiquis authored Mar 20, 2023
2 parents 8f4b698 + 93f088e commit 72ff2fe
Show file tree
Hide file tree
Showing 7 changed files with 295 additions and 212 deletions.
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

0 comments on commit 72ff2fe

Please sign in to comment.