diff options
| author | lucasholten <lucasholten@dreamsolution.nl> | 2024-12-31 15:29:09 +0100 |
|---|---|---|
| committer | lucasholten <lucasholten@dreamsolution.nl> | 2024-12-31 15:48:58 +0100 |
| commit | ccbc3d2cb5bbb9f7e87413115e2b3316ab182c96 (patch) | |
| tree | e34c63a4151165559e8fb7b94711f99de7c89a7f /src/tools | |
| parent | 03b7eb38103183ab4cef415c6b2ef0090cd181e4 (diff) | |
| download | rust-ccbc3d2cb5bbb9f7e87413115e2b3316ab182c96.tar.gz rust-ccbc3d2cb5bbb9f7e87413115e2b3316ab182c96.zip | |
Add back optimizations
Diffstat (limited to 'src/tools')
| -rw-r--r-- | src/tools/rust-analyzer/crates/base-db/src/input.rs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/tools/rust-analyzer/crates/base-db/src/input.rs b/src/tools/rust-analyzer/crates/base-db/src/input.rs index fe5d4091e5d..b263e7382d8 100644 --- a/src/tools/rust-analyzer/crates/base-db/src/input.rs +++ b/src/tools/rust-analyzer/crates/base-db/src/input.rs @@ -499,13 +499,18 @@ impl CrateGraph { /// Extends this crate graph by adding a complete second crate /// graph and adjust the ids in the [`ProcMacroPaths`] accordingly. /// + /// This will deduplicate the crates of the graph where possible. + /// Note that for deduplication to fully work, `self`'s crate dependencies must be sorted by crate id. + /// If the crate dependencies were sorted, the resulting graph from this `extend` call will also + /// have the crate dependencies sorted. + /// /// Returns a map mapping `other`'s IDs to the new IDs in `self`. pub fn extend( &mut self, mut other: CrateGraph, proc_macros: &mut ProcMacroPaths, ) -> FxHashMap<CrateId, CrateId> { - self.sort_deps(); + let m = self.len(); let topo = other.crates_in_topological_order(); let mut id_map: FxHashMap<CrateId, CrateId> = FxHashMap::default(); for topo in topo { @@ -514,9 +519,8 @@ impl CrateGraph { crate_data.dependencies.iter_mut().for_each(|dep| dep.crate_id = id_map[&dep.crate_id]); crate_data.dependencies.sort_by_key(|dep| dep.crate_id); - let find = self.arena.iter().find(|(_, v)| *v == crate_data); - let new_id = - if let Some((k, _)) = find { k } else { self.arena.alloc(crate_data.clone()) }; + let find = self.arena.iter().take(m).find_map(|(k, v)| (v == crate_data).then_some(k)); + let new_id = find.unwrap_or_else(|| self.arena.alloc(crate_data.clone())); id_map.insert(topo, new_id); } |
