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