From 8f9ada8210695905bc7c5055bee0629ad349aed6 Mon Sep 17 00:00:00 2001 From: Eh2406 Date: Wed, 7 Mar 2018 12:57:48 -0500 Subject: [PATCH] restructure `Activations` for better clone --- src/cargo/core/resolver/mod.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/cargo/core/resolver/mod.rs b/src/cargo/core/resolver/mod.rs index 796d9ca86dd..b6531ec22b6 100644 --- a/src/cargo/core/resolver/mod.rs +++ b/src/cargo/core/resolver/mod.rs @@ -357,7 +357,7 @@ struct Context { warnings: RcList, } -type Activations = HashMap>>>; +type Activations = HashMap<(InternedString, SourceId), Rc>>; /// Builds the list of all packages required to build the first argument. pub fn resolve(summaries: &[(Summary, Method)], @@ -389,7 +389,6 @@ pub fn resolve(summaries: &[(Summary, Method)], }; for summary in cx.activations.values() - .flat_map(|v| v.values()) .flat_map(|v| v.iter()) { let cksum = summary.checksum().map(|s| s.to_string()); resolve.checksums.insert(summary.package_id().clone(), cksum); @@ -1305,9 +1304,7 @@ impl Context { method: &Method) -> CargoResult { let id = summary.package_id(); let prev = self.activations - .entry(InternedString::new(id.name())) - .or_insert_with(HashMap::new) - .entry(id.source_id().clone()) + .entry((InternedString::new(id.name()), id.source_id().clone())) .or_insert_with(||Rc::new(Vec::new())); if !prev.iter().any(|c| c == summary) { self.resolve_graph.push(GraphNode::Add(id.clone())); @@ -1368,15 +1365,13 @@ impl Context { } fn prev_active(&self, dep: &Dependency) -> &[Summary] { - self.activations.get(&InternedString::new(dep.name())) - .and_then(|v| v.get(dep.source_id())) + self.activations.get(&(InternedString::new(dep.name()), dep.source_id().clone())) .map(|v| &v[..]) .unwrap_or(&[]) } fn is_active(&self, id: &PackageId) -> bool { - self.activations.get(&InternedString::new(id.name())) - .and_then(|v| v.get(id.source_id())) + self.activations.get(&(InternedString::new(id.name()), id.source_id().clone())) .map(|v| v.iter().any(|s| s.package_id() == id)) .unwrap_or(false) } @@ -1484,7 +1479,6 @@ impl Context { fn check_cycles(resolve: &Resolve, activations: &Activations) -> CargoResult<()> { let summaries: HashMap<&PackageId, &Summary> = activations.values() - .flat_map(|v| v.values()) .flat_map(|v| v.iter()) .map(|s| (s.package_id(), s)) .collect();