From 0ceb7e2fae841be5662b0bf71a33e9d9083ec11d Mon Sep 17 00:00:00 2001 From: zseri Date: Sat, 27 Mar 2021 08:25:06 +0100 Subject: deeper optimizations --- src/makefile/mod.rs | 59 ++++++++++++++++++++++++++--------------------------- 1 file 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; } } } -- cgit v1.2.3