From c45c2a5b2806a8f0d85c1f4eac183804ee58fcde Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Wed, 30 Mar 2022 20:00:05 +0800 Subject: [PATCH] Replace hashmap with hashset Signed-off-by: hi-rustin Better code Signed-off-by: hi-rustin --- src/cargo/ops/tree/graph.rs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/cargo/ops/tree/graph.rs b/src/cargo/ops/tree/graph.rs index 61e9370c99e..ebe63f2a496 100644 --- a/src/cargo/ops/tree/graph.rs +++ b/src/cargo/ops/tree/graph.rs @@ -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::>() + .collect::>() .len() > 1 })