Skip to content

Commit 1be587b

Browse files
committed
parents can use a HashSet
1 parent 94c7bc7 commit 1be587b

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

src/cargo/core/resolver/context.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::collections::HashMap;
22
use std::num::NonZeroU64;
3-
use std::rc::Rc;
43

54
use anyhow::format_err;
65
use log::debug;
@@ -35,7 +34,7 @@ pub struct Context {
3534

3635
/// a way to look up for a package in activations what packages required it
3736
/// and all of the exact deps that it fulfilled.
38-
pub parents: Graph<PackageId, Rc<Vec<Dependency>>>,
37+
pub parents: Graph<PackageId, im_rc::HashSet<Dependency>>,
3938
}
4039

4140
/// When backtracking it can be useful to know how far back to go.
@@ -265,14 +264,14 @@ impl Context {
265264
for (o, e) in self.parents.edges(i) {
266265
let old_link = graph.link(*o, *i);
267266
assert!(old_link.is_empty());
268-
*old_link = e.to_vec();
267+
*old_link = e.iter().cloned().collect();
269268
}
270269
}
271270
graph
272271
}
273272
}
274273

275-
impl Graph<PackageId, Rc<Vec<Dependency>>> {
274+
impl Graph<PackageId, im_rc::HashSet<Dependency>> {
276275
pub fn parents_of(&self, p: PackageId) -> impl Iterator<Item = (PackageId, bool)> + '_ {
277276
self.edges(&p)
278277
.map(|(grand, d)| (*grand, d.iter().any(|x| x.is_public())))
@@ -338,7 +337,7 @@ impl PublicDependency {
338337
parent_pid: PackageId,
339338
is_public: bool,
340339
age: ContextAge,
341-
parents: &Graph<PackageId, Rc<Vec<Dependency>>>,
340+
parents: &Graph<PackageId, im_rc::HashSet<Dependency>>,
342341
) {
343342
// one tricky part is that `candidate_pid` may already be active and
344343
// have public dependencies of its own. So we not only need to mark
@@ -383,7 +382,7 @@ impl PublicDependency {
383382
b_id: PackageId,
384383
parent: PackageId,
385384
is_public: bool,
386-
parents: &Graph<PackageId, Rc<Vec<Dependency>>>,
385+
parents: &Graph<PackageId, im_rc::HashSet<Dependency>>,
387386
) -> Result<
388387
(),
389388
(

src/cargo/core/resolver/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -609,12 +609,10 @@ fn activate(
609609
cx.age += 1;
610610
if let Some((parent, dep)) = parent {
611611
let parent_pid = parent.package_id();
612-
Rc::make_mut(
613-
// add a edge from candidate to parent in the parents graph
614-
cx.parents.link(candidate_pid, parent_pid),
615-
)
612+
// add a edge from candidate to parent in the parents graph
613+
cx.parents.link(candidate_pid, parent_pid)
616614
// and associate dep with that edge
617-
.push(dep.clone());
615+
.insert(dep.clone());
618616
if let Some(public_dependency) = cx.public_dependency.as_mut() {
619617
public_dependency.add_edge(
620618
candidate_pid,

0 commit comments

Comments
 (0)