Skip to content

Commit

Permalink
Replace hashmap with hashset
Browse files Browse the repository at this point in the history
Signed-off-by: hi-rustin <rustin.liu@gmail.com>

Better code

Signed-off-by: hi-rustin <rustin.liu@gmail.com>
  • Loading branch information
Rustin170506 committed Mar 30, 2022
1 parent 58906aa commit c45c2a5
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/cargo/ops/tree/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,27 +234,26 @@ impl<'a> Graph<'a> {
let mut dupes: Vec<(&Node, usize)> = packages
.into_iter()
.filter(|(_name, indexes)| {
let mut pkg_map = HashMap::new();
indexes
.into_iter()
.filter(|(node, _)| {
// Do not treat duplicates on the host or target as duplicates.
let ignore_kind_package = match node {
.map(|(node, _)| {
match node {
Node::Package {
package_id,
features,
..
} => Node::Package {
package_id: package_id.clone(),
features: features.clone(),
kind: CompileKind::Host,
},
} => {
// Do not treat duplicates on the host or target as duplicates.
Node::Package {
package_id: package_id.clone(),
features: features.clone(),
kind: CompileKind::Host,
}
}
_ => unreachable!(),
};
!pkg_map.contains_key(&ignore_kind_package)
&& pkg_map.insert(ignore_kind_package, ()).is_none()
}
})
.collect::<Vec<&(&Node, usize)>>()
.collect::<HashSet<_>>()
.len()
> 1
})
Expand Down

0 comments on commit c45c2a5

Please sign in to comment.