perf(semantic/cfg): lower the visits in neighbors_filtered_by_edge_weight. (#3676)

related to #3407
This commit is contained in:
rzvxa 2024-06-14 16:48:01 +00:00
parent bd8d1152f1
commit 2717a1a5b7

View file

@ -29,19 +29,19 @@ where
while let Some((graph_ix, state)) = q.pop() { while let Some((graph_ix, state)) = q.pop() {
let mut edges = 0; let mut edges = 0;
if visited.contains(&graph_ix) {
for edge in graph.edges_directed(graph_ix, Direction::Outgoing) {
if visited.contains(&edge.target()) {
continue; continue;
} }
visited.insert(graph_ix);
for edge in graph.edges_directed(graph_ix, Direction::Outgoing) {
if let Some(result_of_edge_filtering) = edge_filter(edge.weight()) { if let Some(result_of_edge_filtering) = edge_filter(edge.weight()) {
final_states.push(result_of_edge_filtering); final_states.push(result_of_edge_filtering);
} else { } else {
let opposite_dir_of_edge_graph_ix = edge.target(); let target = edge.target();
let (new_state, keep_walking_this_path) = let (new_state, keep_walking_this_path) = visitor(&target, state.clone());
visitor(&opposite_dir_of_edge_graph_ix, state.clone()); visited.insert(target);
if keep_walking_this_path { if keep_walking_this_path {
q.push((opposite_dir_of_edge_graph_ix, new_state.clone())); q.push((target, new_state.clone()));
} else { } else {
final_states.push(new_state.clone()); final_states.push(new_state.clone());
} }