Skip to content

Commit

Permalink
less clones
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton authored and Eh2406 committed Sep 19, 2019
1 parent 0bce400 commit 384056e
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/cargo/util/dependency_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,15 @@ impl<N: Hash + Eq + Clone, E: Eq + Hash + Clone, V> DependencyQueue<N, E, V> {
}
self.priority = out.into_iter().map(|(n, set)| (n, set.len())).collect();

fn depth<N: Hash + Eq + Clone, E: Hash + Eq + Clone>(
fn depth<'a, N: Hash + Eq + Clone, E: Hash + Eq + Clone>(
key: &N,
map: &HashMap<N, HashMap<E, HashSet<N>>>,
results: &mut HashMap<N, HashSet<N>>,
) -> HashSet<N> {
if let Some(depth) = results.get(key) {
results: &'a mut HashMap<N, HashSet<N>>,
) -> &'a HashSet<N> {
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());

Expand All @@ -108,12 +109,12 @@ impl<N: Hash + Eq + Clone, E: Eq + Hash + Clone, V> DependencyQueue<N, E, V> {
.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;
}
}

Expand Down

0 comments on commit 384056e

Please sign in to comment.