Skip to content

Commit 2717a1a

Browse files
committed
perf(semantic/cfg): lower the visits in neighbors_filtered_by_edge_weight. (#3676)
related to #3407
1 parent bd8d115 commit 2717a1a

File tree

1 file changed

+8
-8
lines changed
  • crates/oxc_semantic/src

1 file changed

+8
-8
lines changed

crates/oxc_semantic/src/pg.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ where
2929

3030
while let Some((graph_ix, state)) = q.pop() {
3131
let mut edges = 0;
32-
if visited.contains(&graph_ix) {
33-
continue;
34-
}
35-
visited.insert(graph_ix);
32+
3633
for edge in graph.edges_directed(graph_ix, Direction::Outgoing) {
34+
if visited.contains(&edge.target()) {
35+
continue;
36+
}
3737
if let Some(result_of_edge_filtering) = edge_filter(edge.weight()) {
3838
final_states.push(result_of_edge_filtering);
3939
} else {
40-
let opposite_dir_of_edge_graph_ix = edge.target();
41-
let (new_state, keep_walking_this_path) =
42-
visitor(&opposite_dir_of_edge_graph_ix, state.clone());
40+
let target = edge.target();
41+
let (new_state, keep_walking_this_path) = visitor(&target, state.clone());
42+
visited.insert(target);
4343
if keep_walking_this_path {
44-
q.push((opposite_dir_of_edge_graph_ix, new_state.clone()));
44+
q.push((target, new_state.clone()));
4545
} else {
4646
final_states.push(new_state.clone());
4747
}

0 commit comments

Comments
 (0)