aboutsummaryrefslogtreecommitdiff
path: root/crates/base_db/src
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-03-16 14:53:34 +0000
committerLukas Wirth <[email protected]>2021-03-16 14:53:34 +0000
commitbebee2106de7bbd20f54d7f55d5c56dba0d636b6 (patch)
tree327a17b65055010f2d7c8ce5477723b9f3398bf2 /crates/base_db/src
parent75fafd6fcc010c71d770d19bea4b744b92c5267b (diff)
Don't repeat work in transitive_reverse_dependencies
Diffstat (limited to 'crates/base_db/src')
-rw-r--r--crates/base_db/src/input.rs21
1 files changed, 10 insertions, 11 deletions
diff --git a/crates/base_db/src/input.rs b/crates/base_db/src/input.rs
index 06f1c14f5..d0def2181 100644
--- a/crates/base_db/src/input.rs
+++ b/crates/base_db/src/input.rs
@@ -281,24 +281,23 @@ impl CrateGraph {
281 ) -> impl Iterator<Item = CrateId> + '_ { 281 ) -> impl Iterator<Item = CrateId> + '_ {
282 let mut worklist = vec![of]; 282 let mut worklist = vec![of];
283 let mut rev_deps = FxHashSet::default(); 283 let mut rev_deps = FxHashSet::default();
284 let mut inverted_graph = FxHashMap::default(); 284 let mut inverted_graph = FxHashMap::<_, Vec<_>>::default();
285 self.arena.iter().for_each(|(&krate, data)| { 285 self.arena.iter().for_each(|(&krate, data)| {
286 data.dependencies.iter().for_each(|dep| { 286 data.dependencies
287 inverted_graph.entry(dep.crate_id).or_insert_with(Vec::default).push(krate) 287 .iter()
288 }) 288 .for_each(|dep| inverted_graph.entry(dep.crate_id).or_default().push(krate))
289 }); 289 });
290 290
291 while let Some(krate) = worklist.pop() { 291 while let Some(krate) = worklist.pop() {
292 if !rev_deps.insert(krate) { 292 if let Some(krate_rev_deps) = inverted_graph.get(&krate) {
293 continue; 293 krate_rev_deps
294 } 294 .iter()
295 295 .copied()
296 if let Some(rev_deps) = inverted_graph.get(&krate) { 296 .filter(|&rev_dep| rev_deps.insert(rev_dep))
297 worklist.extend(rev_deps); 297 .for_each(|rev_dep| worklist.push(rev_dep));
298 } 298 }
299 } 299 }
300 300
301 rev_deps.remove(&of);
302 rev_deps.into_iter() 301 rev_deps.into_iter()
303 } 302 }
304 303