Skip to content

Commit 1aa10f9

Browse files
committed
fixes
1 parent fddd5e4 commit 1aa10f9

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/build/compile/dependency_cycle.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,18 @@ fn find_shortest_cycle(modules: &Vec<(&String, &Module)>) -> Vec<String> {
2323
for (name, module) in modules {
2424
let deps: Vec<String> = module.deps.iter().cloned().collect();
2525

26-
// Update the graph
27-
*graph.get_mut(&name.to_string()).unwrap() = deps.clone();
28-
2926
// Update in-degrees
30-
for dep in deps {
31-
if let Some(count) = in_degrees.get_mut(&dep) {
27+
for dep in &deps {
28+
if let Some(count) = in_degrees.get_mut(dep) {
3229
*count += 1;
3330
}
3431
}
32+
33+
// Update the graph
34+
*graph.get_mut(&name.to_string()).unwrap() = deps.clone();
3535
}
36+
// Remove all nodes in the graph that have no incoming edges
37+
graph.retain(|_, deps| !deps.is_empty());
3638

3739
// OPTIMIZATION 1: Start with nodes that are more likely to be in cycles
3840
// Sort nodes by their connectivity (in-degree + out-degree)
@@ -56,10 +58,8 @@ fn find_shortest_cycle(modules: &Vec<(&String, &Module)>) -> Vec<String> {
5658
continue;
5759
}
5860

59-
// Skip nodes with no outgoing edges or no incoming edges
60-
if graph.get(&start_node).map_or(true, |v| v.is_empty())
61-
|| in_degrees.get(&start_node).map_or(true, |&d| d == 0)
62-
{
61+
// Skip nodes with no incoming edges
62+
if in_degrees.get(&start_node).map_or(true, |&d| d == 0) {
6363
no_cycle_cache.insert(start_node.clone());
6464
continue;
6565
}

0 commit comments

Comments
 (0)