From c7eaee3d866a657c028c3d90f8fddee8b97c7b97 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Wed, 28 Dec 2022 15:02:10 +0900 Subject: [PATCH] matchers: remove redundant files set from FilesMatcher, use Dirs --- lib/src/matchers.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/src/matchers.rs b/lib/src/matchers.rs index 262fec2ce..8784ae5b8 100644 --- a/lib/src/matchers.rs +++ b/lib/src/matchers.rs @@ -97,7 +97,6 @@ impl Matcher for EverythingMatcher { #[derive(PartialEq, Eq, Debug)] pub struct FilesMatcher { - files: HashSet, dirs: Dirs, } @@ -107,13 +106,13 @@ impl FilesMatcher { for f in &files { dirs.add_file(f); } - FilesMatcher { files, dirs } + FilesMatcher { dirs } } } impl Matcher for FilesMatcher { fn matches(&self, file: &RepoPath) -> bool { - self.files.contains(file) + self.dirs.get(file).map(|sub| sub.is_file).unwrap_or(false) } fn visit(&self, dir: &RepoPath) -> Visit { @@ -401,6 +400,12 @@ mod tests { RepoPath::from_internal_string("file4"), }); + assert!(!m.matches(&RepoPath::from_internal_string("dir1"))); + assert!(!m.matches(&RepoPath::from_internal_string("dir1/subdir1"))); + assert!(m.matches(&RepoPath::from_internal_string("dir1/subdir1/file1"))); + assert!(m.matches(&RepoPath::from_internal_string("dir1/subdir1/file2"))); + assert!(!m.matches(&RepoPath::from_internal_string("dir1/subdir1/file3"))); + assert_eq!( m.visit(&RepoPath::root()), Visit::sets(