Skip to content

Commit

Permalink
chore: using simpler api for perf
Browse files Browse the repository at this point in the history
  • Loading branch information
williamfzc committed Sep 8, 2024
1 parent a231b5b commit d1a80fd
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions src/symbol.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use petgraph::algo::all_simple_paths;
use petgraph::graph::{NodeIndex, UnGraph};
use petgraph::prelude::EdgeRef;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -251,26 +250,24 @@ impl SymbolGraph {
}

pub fn pairs_between_files(&self, src_file: &String, dst_file: &String) -> Vec<DefRefPair> {
if let (Some(src_index), Some(dst_index)) = (
self.file_mapping.get(src_file),
self.file_mapping.get(dst_file),
) {
// file -> symbol -> symbol -> file
// so at most 2
let pairs: Vec<_> =
all_simple_paths::<Vec<_>, _>(&self.g, *src_index, *dst_index, 1, Some(2))
.filter(|each| each.len() == 4)
.map(|each| DefRefPair {
src_symbol: self.g[each[1]].get_symbol().unwrap().clone(),
dst_symbol: self.g[each[2]].get_symbol().unwrap().clone(),
})
.filter(|each| each.src_symbol.kind == SymbolKind::DEF)
.collect();
return pairs;
let defs = self.list_definitions(src_file);
let refs = self.list_references(dst_file);

let mut pairs = vec![];

for each_def in &defs {
let def_index = self.symbol_mapping[&each_def.id()];
for each_ref in &refs {
let ref_index = self.symbol_mapping[&each_ref.id()];
if self.g.contains_edge(def_index, ref_index) {
pairs.push(DefRefPair {
src_symbol: each_def.clone(),
dst_symbol: each_ref.clone(),
});
}
}
}

// fallback
vec![]
pairs
}
}

Expand Down

0 comments on commit d1a80fd

Please sign in to comment.