summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2022-11-10 17:47:36 -0600
committerToby Vincent <tobyv13@gmail.com>2022-11-10 17:47:36 -0600
commit6b9b3c885c1238dcbe512890badc4c5f93c8222f (patch)
tree5f9229a48641508559515d4e4f013389928b30f3
parent4cac42d2299cecdc3d6a7f6d7661137da338278b (diff)
perf: remove unnecessary clones and Option
-rw-r--r--src/cli.rs4
-rw-r--r--src/paths.rs37
2 files changed, 17 insertions, 24 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 521809e..353c293 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -48,8 +48,8 @@ impl Cli {
crate::paths::Config {
paths: self
.path
- .to_owned()
- .into_iter()
+ .iter()
+ .cloned()
.map(|p| PathEntry {
path: p,
hidden: self.hidden,
diff --git a/src/paths.rs b/src/paths.rs
index de6a2dd..719eec4 100644
--- a/src/paths.rs
+++ b/src/paths.rs
@@ -8,52 +8,45 @@ pub use error::Error;
mod config;
mod error;
-#[derive(Default)]
pub struct Paths {
- path_entries: Vec<PathEntry>,
- paths_iter: Option<IntoIter<PathEntry>>,
+ paths_iter: IntoIter<PathEntry>,
iter: Option<Walk>,
}
impl Paths {
pub fn new(path_entries: Vec<PathEntry>) -> Self {
Self {
- path_entries,
- ..Default::default()
+ paths_iter: path_entries.into_iter(),
+ iter: None,
}
}
}
impl From<&Config> for Paths {
fn from(value: &Config) -> Self {
- Paths {
- path_entries: value.paths.to_owned(),
- ..Default::default()
- }
+ Self::new(value.paths.to_owned())
}
}
impl Iterator for Paths {
type Item = PathBuf;
+ #[tracing::instrument(skip(self))]
fn next(&mut self) -> Option<Self::Item> {
loop {
match self.iter.as_mut().and_then(|iter| iter.next()) {
Some(Ok(d)) => return Some(d.into_path()),
Some(Err(err)) => warn!("{:?}", err),
- None => match self.paths_iter.as_mut() {
- Some(paths_iter) => {
- let next = paths_iter.next()?;
- self.iter = Some(
- WalkBuilder::new(next.path)
- .standard_filters(true)
- .max_depth(next.recurse)
- .hidden(next.hidden)
- .build(),
- );
- }
- None => self.paths_iter = Some(self.path_entries.to_owned().into_iter()),
- },
+ None => {
+ let next = self.paths_iter.next()?;
+ self.iter = Some(
+ WalkBuilder::new(next.path)
+ .standard_filters(true)
+ .max_depth(next.recurse)
+ .hidden(next.hidden)
+ .build(),
+ );
+ }
};
}
}