fix: remove IO on transformed_keywords

This commit is contained in:
Azalea Colburn 2025-03-16 00:47:53 -07:00
parent 57520a15a3
commit 1259156382
No known key found for this signature in database
1 changed files with 13 additions and 11 deletions

View File

@ -78,7 +78,7 @@ impl Query {
fn get_stream<'a>(&self, db: &'a mut Database, now: Epoch) -> Result<Stream<'a>> { fn get_stream<'a>(&self, db: &'a mut Database, now: Epoch) -> Result<Stream<'a>> {
let mut options = StreamOptions::new(now) let mut options = StreamOptions::new(now)
.with_keywords(self.transfomed_keywords()) .with_keywords(self.transformed_keywords())
.with_exclude(config::exclude_dirs()?); .with_exclude(config::exclude_dirs()?);
if !self.all { if !self.all {
let resolve_symlinks = config::resolve_symlinks(); let resolve_symlinks = config::resolve_symlinks();
@ -119,19 +119,21 @@ impl Query {
} }
/// ## Returns /// ## Returns
/// `self.keywords` with file paths transformed into their parent directory /// `self.keywords` with file paths transformed into
/// paths and directory paths unchanged /// their parent directory paths, directory paths unchanged
/// ///
/// ## Warning /// ## Notes
/// Clones self.keywords /// - Heap allocates an iterator of Strings with length of self.keywords
fn transfomed_keywords(&self) -> impl Iterator<Item = String> + use<'_> { /// - Only uses sans-IO Path methods
fn transformed_keywords(&self) -> impl Iterator<Item = String> + use<'_> {
self.keywords.iter().map(|keyword| { self.keywords.iter().map(|keyword| {
if std::path::Path::new(keyword).is_file() { let path = std::path::Path::new(keyword);
let dirs: Vec<&str> = keyword.split("/").collect(); match path.parent() {
dirs.split_last().unwrap().1.join("/").to_string() None => keyword,
} else { Some(path) if path.to_str() == Some("") => keyword,
keyword.to_string() Some(path) => path.to_str().unwrap(),
} }
.to_string()
}) })
} }
} }