]> git.proxmox.com Git - cargo.git/commitdiff
Replace hashmap with hashset
authorhi-rustin <rustin.liu@gmail.com>
Wed, 30 Mar 2022 12:00:05 +0000 (20:00 +0800)
committerhi-rustin <rustin.liu@gmail.com>
Wed, 30 Mar 2022 14:07:31 +0000 (22:07 +0800)
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
Better code

Signed-off-by: hi-rustin <rustin.liu@gmail.com>
src/cargo/ops/tree/graph.rs

index 61e9370c99eb385fc1ec16f4a4c27edf47de754c..ebe63f2a496be8cdcb41bf74bb7f53211cc0c4c9 100644 (file)
@@ -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
             })