From f86346c4aaac4144630fd3a5d1a1564fc8b8612b Mon Sep 17 00:00:00 2001 From: Eh2406 Date: Thu, 22 Mar 2018 16:18:58 -0400 Subject: [PATCH] remove some loops --- src/cargo/core/resolver/mod.rs | 54 +++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/src/cargo/core/resolver/mod.rs b/src/cargo/core/resolver/mod.rs index 30d65e18a..1616a9c55 100644 --- a/src/cargo/core/resolver/mod.rs +++ b/src/cargo/core/resolver/mod.rs @@ -1294,30 +1294,38 @@ fn activate_deps_loop( } } if !has_past_conflicting_dep { - // TODO: this is ugly, replace! if let Some(rel_deps) = past_conflict_triggers.get(&pid) { - 'deps: for debs in remaining_deps.iter() { - for (_, (other_dep, _, _)) in debs.remaining_siblings.clone() { - if rel_deps.contains(&other_dep) { - if let Some(conflict) = past_conflicting_activations - .get(&other_dep) - .and_then(|past_bad| { - past_bad.iter().find(|con| { - con.contains_key(&pid) - && cx.is_conflicting(None, con) - }) - }) { - let mut conflict = conflict.clone(); - let rel = conflict.get(&pid).unwrap().clone(); - conflict.insert(debs.parent.package_id().clone(), rel); - conflict.remove(&pid); - - conflicting_activations.extend(conflict); - has_past_conflicting_dep = true; - break 'deps; - } - } - } + if let Some((other_parent, conflict)) = remaining_deps + .iter() + .flat_map(|other| { + other + .remaining_siblings + .clone() + .filter(|&(_, (ref d, _, _))| rel_deps.contains(d)) + .map(move |(_, (d, _, _))| { + (other.parent.package_id().clone(), d) + }) + }) + .filter_map(|(other_parent, other_deps)| { + past_conflicting_activations + .get(&other_deps) + .map(|v| (other_parent, v)) + }) + .flat_map(|(other_parent, past_bad)| { + past_bad + .iter() + .filter(|con| con.contains_key(&pid)) + .map(move |c| (other_parent.clone(), c)) + }) + .find(|&(_, ref con)| cx.is_conflicting(None, con)) + { + let mut conflict = conflict.clone(); + let rel = conflict.get(&pid).unwrap().clone(); + conflict.insert(other_parent.clone(), rel); + conflict.remove(&pid); + + conflicting_activations.extend(conflict); + has_past_conflicting_dep = true; } } } -- 2.30.2