diff options
author | zseri <zseri.devel@ytrizja.de> | 2021-03-27 08:25:06 +0100 |
---|---|---|
committer | zseri <zseri.devel@ytrizja.de> | 2021-03-27 08:25:06 +0100 |
commit | 0ceb7e2fae841be5662b0bf71a33e9d9083ec11d (patch) | |
tree | bcf55b188552ba6ec7a82b49142991ee03967ee4 /src/makefile/mod.rs | |
parent | 95b81e721297cf1dd481d744916ded04f91bebf0 (diff) | |
download | makers-0ceb7e2fae841be5662b0bf71a33e9d9083ec11d.tar.gz makers-0ceb7e2fae841be5662b0bf71a33e9d9083ec11d.zip |
deeper optimizations
Diffstat (limited to 'src/makefile/mod.rs')
-rw-r--r-- | src/makefile/mod.rs | 59 |
1 files changed, 29 insertions, 30 deletions
diff --git a/src/makefile/mod.rs b/src/makefile/mod.rs index dae742f..735c8aa 100644 --- a/src/makefile/mod.rs +++ b/src/makefile/mod.rs @@ -565,13 +565,9 @@ impl<'a> Makefile<'a> { let targets = self.targets.borrow(); let mut new_target = None; let exists_but_infer_anyway = if follow_gnu { - match targets.get(name) { - Some(target) => { - let target = target.borrow(); - target.commands.is_empty() - } - None => false, - } + targets + .get(name) + .map_or(false, |target| target.borrow().commands.is_empty()) } else { false }; @@ -585,31 +581,34 @@ impl<'a> Makefile<'a> { // targets. If the .s1 suffix is found in .SUFFIXES... if self.special_target_has_prereq(".SUFFIXES", &suffix) || suffix.is_empty() { // the inference rules shall be searched in the order defined... - 'rules: for rule in &self.inference_rules { + 'rules: for rule in self + .inference_rules + .iter() // for the first .s2.s1 rule... - if rule.product == suffix { - // whose prerequisite file ($*.s2) exists. - let prereq_path = - Path::new(name).with_extension(rule.prereq.trim_start_matches('.')); - let prereq_path_options = if prereq_path.is_absolute() { - vec![prereq_path] - } else { - let mut options = vec![prereq_path.clone()]; - options - .extend(vpath_options.iter().map(|vpath| vpath.join(&prereq_path))); - options - }; - for prereq in prereq_path_options { - if prereq.exists() { - new_target = Some(Target { - name: name.into(), - prerequisites: vec![prereq.to_string_lossy().into()], - commands: rule.commands.clone(), - already_updated: Cell::new(false), - }); - break 'rules; + .filter(|rule| rule.product == suffix) + { + // whose prerequisite file ($*.s2) exists. + let prereq_path = + Path::new(name).with_extension(rule.prereq.trim_start_matches('.')); + if let Some(prereq) = std::iter::once(prereq_path.clone()) + .chain( + if prereq_path.is_absolute() { + None + } else { + Some(vpath_options.iter().map(|vpath| vpath.join(&prereq_path))) } - } + .into_iter() + .flatten(), + ) + .find(|prereq| prereq.exists()) + { + new_target = Some(Target { + name: name.into(), + prerequisites: vec![prereq.to_string_lossy().into()], + commands: rule.commands.clone(), + already_updated: Cell::new(false), + }); + break 'rules; } } } |