1
0
Fork 0
mirror of https://github.com/archtechx/todo-system.git synced 2025-12-12 09:04:03 +00:00

perf: store glob exclude patterns instead of traversing glob(...)

Previously add_excludes_from_gitignore() would use glob() and
recursively traverse the generated paths to add them to excludes.

Now we store excludes as an enum - Path or Glob - and use the glob
crate's `Pattern.matches_path()` as needed, instead of the preemptive
traversal.
This commit is contained in:
Samuel Štancl 2025-09-13 22:21:48 +02:00
parent ea031d81f0
commit 32a57ab5fb
2 changed files with 33 additions and 16 deletions

View file

@ -4,7 +4,7 @@ use std::path::PathBuf;
use clap::{Parser, ArgAction};
use crate::entries::Entry;
use crate::render::render_entries;
use crate::scan::{Stats, scan_dir, scan_todo_file, scan_readme_file};
use crate::scan::{Stats, scan_dir, scan_todo_file, scan_readme_file, Exclude};
pub mod scan;
pub mod render;
@ -43,7 +43,7 @@ fn main() {
let root_dir: PathBuf = std::env::current_dir().unwrap();
let mut paths: Vec<PathBuf> = vec![];
let mut excludes: Vec<PathBuf> = vec![];
let mut excludes: Vec<Exclude> = vec![];
let mut entries: Vec<Entry> = vec![];
let mut stats = Stats::new(args.verbose);
@ -68,7 +68,7 @@ fn main() {
if path.exists() {
if let Ok(realpath) = canonicalize(path) {
excludes.push(realpath);
excludes.push(Exclude::Path(realpath));
}
}
}
@ -80,13 +80,13 @@ fn main() {
readme_path.push(&args.readme);
if todos_path.exists() {
excludes.push(todos_path.clone());
excludes.push(Exclude::Path(todos_path.clone()));
scan_todo_file(&todos_path, &mut entries).unwrap();
}
if readme_path.exists() {
excludes.push(readme_path.clone());
excludes.push(Exclude::Path(readme_path.clone()));
scan_readme_file(&readme_path, &mut entries).unwrap();
}