Skip to content

Commit

Permalink
refactor: use map.contains_key() instead of iterating
Browse files Browse the repository at this point in the history
using map.contains_key is easier to understand and probably has better
lookup time

Signed-off-by: Luke-zhang-04 <luke.zhang2004dev@gmail.com>
  • Loading branch information
Luke-zhang-04 committed Nov 5, 2020
1 parent 6fdb61d commit 0b8caa0
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions src/onefetch/deps/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ impl DependencyDetector {
DependencyDetector { package_managers }
}

fn is_package_file(&self, file_name: &str) -> bool {
self.package_managers.iter().any(|(package_manager_file_name, _)| {
file_name.starts_with(package_manager_file_name)
})
}

pub fn get_deps_info(&self, dir: &str) -> Result<String> {
let deps = fs::read_dir(dir)
.chain_err(|| "Could not read directory")?
Expand All @@ -56,7 +50,7 @@ impl DependencyDetector {
&& entry
.file_name()
.map(OsStr::to_string_lossy)
.map(|s| self.is_package_file(s.as_ref()))
.map(|s| self.package_managers.contains_key(s.as_ref()))
.unwrap_or_default()
})
.map(|entry| {
Expand Down

0 comments on commit 0b8caa0

Please sign in to comment.