mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 09:27:27 +00:00
Don't repeat work in transitive_reverse_dependencies
This commit is contained in:
parent
75fafd6fcc
commit
bebee2106d
1 changed files with 10 additions and 11 deletions
|
@ -281,24 +281,23 @@ impl CrateGraph {
|
||||||
) -> impl Iterator<Item = CrateId> + '_ {
|
) -> impl Iterator<Item = CrateId> + '_ {
|
||||||
let mut worklist = vec![of];
|
let mut worklist = vec![of];
|
||||||
let mut rev_deps = FxHashSet::default();
|
let mut rev_deps = FxHashSet::default();
|
||||||
let mut inverted_graph = FxHashMap::default();
|
let mut inverted_graph = FxHashMap::<_, Vec<_>>::default();
|
||||||
self.arena.iter().for_each(|(&krate, data)| {
|
self.arena.iter().for_each(|(&krate, data)| {
|
||||||
data.dependencies.iter().for_each(|dep| {
|
data.dependencies
|
||||||
inverted_graph.entry(dep.crate_id).or_insert_with(Vec::default).push(krate)
|
.iter()
|
||||||
})
|
.for_each(|dep| inverted_graph.entry(dep.crate_id).or_default().push(krate))
|
||||||
});
|
});
|
||||||
|
|
||||||
while let Some(krate) = worklist.pop() {
|
while let Some(krate) = worklist.pop() {
|
||||||
if !rev_deps.insert(krate) {
|
if let Some(krate_rev_deps) = inverted_graph.get(&krate) {
|
||||||
continue;
|
krate_rev_deps
|
||||||
}
|
.iter()
|
||||||
|
.copied()
|
||||||
if let Some(rev_deps) = inverted_graph.get(&krate) {
|
.filter(|&rev_dep| rev_deps.insert(rev_dep))
|
||||||
worklist.extend(rev_deps);
|
.for_each(|rev_dep| worklist.push(rev_dep));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rev_deps.remove(&of);
|
|
||||||
rev_deps.into_iter()
|
rev_deps.into_iter()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue