Skip to content

Commit 39b168b

Browse files
committed
graph can use HashSet
1 parent 1be587b commit 39b168b

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

src/cargo/core/resolver/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ impl Context {
254254
.collect()
255255
}
256256

257-
pub fn graph(&self) -> Graph<PackageId, Vec<Dependency>> {
258-
let mut graph: Graph<PackageId, Vec<Dependency>> = Graph::new();
257+
pub fn graph(&self) -> Graph<PackageId, std::collections::HashSet<Dependency>> {
258+
let mut graph: Graph<PackageId, std::collections::HashSet<Dependency>> = Graph::new();
259259
self.activations
260260
.values()
261261
.for_each(|(r, _)| graph.add(r.package_id()));

src/cargo/core/resolver/resolve.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub struct Resolve {
1818
/// A graph, whose vertices are packages and edges are dependency specifications
1919
/// from `Cargo.toml`. We need a `Vec` here because the same package
2020
/// might be present in both `[dependencies]` and `[build-dependencies]`.
21-
graph: Graph<PackageId, Vec<Dependency>>,
21+
graph: Graph<PackageId, HashSet<Dependency>>,
2222
/// Replacements from the `[replace]` table.
2323
replacements: HashMap<PackageId, PackageId>,
2424
/// Inverted version of `replacements`.
@@ -70,7 +70,7 @@ pub enum ResolveVersion {
7070

7171
impl Resolve {
7272
pub fn new(
73-
graph: Graph<PackageId, Vec<Dependency>>,
73+
graph: Graph<PackageId, HashSet<Dependency>>,
7474
replacements: HashMap<PackageId, PackageId>,
7575
features: HashMap<PackageId, Vec<InternedString>>,
7676
checksums: HashMap<PackageId, Option<String>>,
@@ -264,18 +264,18 @@ unable to verify that `{0}` is the same as when the lockfile was generated
264264
self.graph.iter().cloned()
265265
}
266266

267-
pub fn deps(&self, pkg: PackageId) -> impl Iterator<Item = (PackageId, &[Dependency])> {
267+
pub fn deps(&self, pkg: PackageId) -> impl Iterator<Item = (PackageId, &HashSet<Dependency>)> {
268268
self.deps_not_replaced(pkg)
269269
.map(move |(id, deps)| (self.replacement(id).unwrap_or(id), deps))
270270
}
271271

272272
pub fn deps_not_replaced(
273273
&self,
274274
pkg: PackageId,
275-
) -> impl Iterator<Item = (PackageId, &[Dependency])> {
275+
) -> impl Iterator<Item = (PackageId, &HashSet<Dependency>)> {
276276
self.graph
277277
.edges(&pkg)
278-
.map(|(id, deps)| (*id, deps.as_slice()))
278+
.map(|(id, deps)| (*id, deps))
279279
}
280280

281281
pub fn replacement(&self, pkg: PackageId) -> Option<PackageId> {
@@ -325,8 +325,9 @@ unable to verify that `{0}` is the same as when the lockfile was generated
325325
to: PackageId,
326326
to_target: &Target,
327327
) -> CargoResult<String> {
328+
let empty_set: HashSet<Dependency> = HashSet::new();
328329
let deps = if from == to {
329-
&[]
330+
&empty_set
330331
} else {
331332
self.dependencies_listed(from, to)
332333
};
@@ -349,7 +350,7 @@ unable to verify that `{0}` is the same as when the lockfile was generated
349350
Ok(name)
350351
}
351352

352-
fn dependencies_listed(&self, from: PackageId, to: PackageId) -> &[Dependency] {
353+
fn dependencies_listed(&self, from: PackageId, to: PackageId) -> &HashSet<Dependency> {
353354
// We've got a dependency on `from` to `to`, but this dependency edge
354355
// may be affected by [replace]. If the `to` package is listed as the
355356
// target of a replacement (aka the key of a reverse replacement map)

src/cargo/ops/cargo_output_metadata.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,7 @@ fn build_resolve_graph_r(
184184
CompileKind::Host => true,
185185
})
186186
.filter_map(|(dep_id, deps)| {
187-
let mut dep_kinds: Vec<_> = deps.iter().map(DepKindInfo::from).collect();
188-
// Duplicates may appear if the same package is used by different
189-
// members of a workspace with different features selected.
190-
dep_kinds.sort_unstable();
191-
dep_kinds.dedup();
187+
let dep_kinds: Vec<_> = deps.iter().map(DepKindInfo::from).collect();
192188
package_map
193189
.get(&dep_id)
194190
.and_then(|pkg| pkg.targets().iter().find(|t| t.is_lib()))

0 commit comments

Comments
 (0)