From 2d87ed9a4dc8554bff082c97335b2a48659c7381 Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Fri, 2 Apr 2021 22:40:27 -0600 Subject: simplify MakefileReader.targets it doesn't need interior mutability so why put up with the cruft from that? --- src/makefile/input.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/makefile/input.rs b/src/makefile/input.rs index fda81d0..e8a4a42 100644 --- a/src/makefile/input.rs +++ b/src/makefile/input.rs @@ -90,7 +90,7 @@ fn inference_match<'a>( pub struct MakefileReader<'a> { inference_rules: Vec, macros: MacroSet<'static, 'static>, - targets: RefCell>>>, + targets: HashMap, pub first_non_special_target: Option, args: &'a Args, // TODO borrow warnings from Python version @@ -106,11 +106,7 @@ impl<'a> MakefileReader<'a> { if !args.no_builtin_rules { inference_rules.extend(builtin_inference_rules()); macros.add_builtins(); - targets.extend( - builtin_targets() - .into_iter() - .map(|t| (t.name.clone(), Rc::new(RefCell::new(t)))), - ); + targets.extend(builtin_targets().into_iter().map(|t| (t.name.clone(), t))); } macros.add_env(); @@ -128,7 +124,7 @@ impl<'a> MakefileReader<'a> { MakefileReader { inference_rules, macros, - targets: RefCell::new(targets), + targets, first_non_special_target, args, } @@ -337,13 +333,11 @@ impl<'a> MakefileReader<'a> { if self.first_non_special_target.is_none() && !target.starts_with('.') { self.first_non_special_target = Some(target.into()); } - let mut targets = self.targets.borrow_mut(); - match targets.get_mut(target) { + match self.targets.get_mut(target) { Some(old_target) if commands.is_empty() && !(target == ".SUFIXES" && prerequisites.is_empty()) => { - let mut old_target = old_target.borrow_mut(); let new_prerequisites = prerequisites .iter() .filter(|x| !old_target.prerequisites.contains(x)) @@ -358,7 +352,7 @@ impl<'a> MakefileReader<'a> { commands: commands.clone(), already_updated: Cell::new(false), }; - targets.insert(target.into(), Rc::new(RefCell::new(new_target))); + self.targets.insert(target.into(), new_target); } } } @@ -461,7 +455,13 @@ impl<'a> From> for super::Makefile<'a> { Self { inference_rules: reader.inference_rules, macros: reader.macros, - targets: reader.targets, + targets: RefCell::new( + reader + .targets + .into_iter() + .map(|(k, v)| (k, Rc::new(RefCell::new(v)))) + .collect(), + ), first_non_special_target: reader.first_non_special_target, args: reader.args, } @@ -556,7 +556,7 @@ mod test { MakefileReader { inference_rules: vec![], macros: MacroSet::new(), - targets: RefCell::new(HashMap::new()), + targets: HashMap::new(), first_non_special_target: None, args, } @@ -642,7 +642,7 @@ clean: let args = Args::empty(); let mut makefile = empty_makefile(&args); makefile.and_read(Cursor::new(file))?; - assert!(makefile.targets.borrow().contains_key("server")); + assert!(makefile.targets.contains_key("server")); Ok(()) } } -- cgit v1.2.3