From 384056e082c5455422e984f19bb0dd3714bb8c24 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 19 Sep 2019 16:43:26 -0400 Subject: [PATCH] less clones --- src/cargo/util/dependency_queue.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/cargo/util/dependency_queue.rs b/src/cargo/util/dependency_queue.rs index 21886c0ee34..94654950785 100644 --- a/src/cargo/util/dependency_queue.rs +++ b/src/cargo/util/dependency_queue.rs @@ -88,14 +88,15 @@ impl DependencyQueue { } self.priority = out.into_iter().map(|(n, set)| (n, set.len())).collect(); - fn depth( + fn depth<'a, N: Hash + Eq + Clone, E: Hash + Eq + Clone>( key: &N, map: &HashMap>>, - results: &mut HashMap>, - ) -> HashSet { - if let Some(depth) = results.get(key) { + results: &'a mut HashMap>, + ) -> &'a HashSet { + if results.contains_key(key) { + let depth = &results[key]; assert!(!depth.is_empty(), "cycle in DependencyQueue"); - return depth.clone(); + return depth; } results.insert(key.clone(), HashSet::new()); @@ -108,12 +109,12 @@ impl DependencyQueue { .flat_map(|it| it.values()) .flat_map(|set| set) { - set.extend(depth(dep, map, results)) + set.extend(depth(dep, map, results).iter().cloned()) } - *results.get_mut(key).unwrap() = set.clone(); - - set + let slot = results.get_mut(key).unwrap(); + *slot = set; + return &*slot; } }