aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2021-06-10 22:10:09 +0100
committerKirill Bulatov <[email protected]>2021-06-10 22:10:09 +0100
commit690cd953273317ee4f3eaefd95bbd3538e929522 (patch)
tree47210c5b426680b218362ca4dd58f2ee79cf6244 /crates/hir_def
parent3aaf07b8cb9a17669894db9f3e6afdb302676fdb (diff)
Reduce fst_path calls
Diffstat (limited to 'crates/hir_def')
-rw-r--r--crates/hir_def/src/import_map.rs16
1 files changed, 5 insertions, 11 deletions
diff --git a/crates/hir_def/src/import_map.rs b/crates/hir_def/src/import_map.rs
index 2055edc95..404e3e153 100644
--- a/crates/hir_def/src/import_map.rs
+++ b/crates/hir_def/src/import_map.rs
@@ -1,6 +1,6 @@
1//! A map of all publicly exported items in a crate. 1//! A map of all publicly exported items in a crate.
2 2
3use std::{cmp::Ordering, fmt, hash::BuildHasherDefault, sync::Arc}; 3use std::{fmt, hash::BuildHasherDefault, sync::Arc};
4 4
5use base_db::CrateId; 5use base_db::CrateId;
6use fst::{self, Streamer}; 6use fst::{self, Streamer};
@@ -73,7 +73,7 @@ impl ImportMap {
73 let mut import_map = collect_import_map(db, krate); 73 let mut import_map = collect_import_map(db, krate);
74 74
75 let mut importables = import_map.map.iter().collect::<Vec<_>>(); 75 let mut importables = import_map.map.iter().collect::<Vec<_>>();
76 importables.sort_by(cmp); 76 importables.sort_by_cached_key(|(_, import_info)| fst_path(&import_info.path));
77 77
78 // Build the FST, taking care not to insert duplicate values. 78 // Build the FST, taking care not to insert duplicate values.
79 79
@@ -81,13 +81,13 @@ impl ImportMap {
81 let mut last_batch_start = 0; 81 let mut last_batch_start = 0;
82 82
83 for idx in 0..importables.len() { 83 for idx in 0..importables.len() {
84 if let Some(next_item) = importables.get(idx + 1) { 84 let key = fst_path(&importables[last_batch_start].1.path);
85 if cmp(&importables[last_batch_start], next_item) == Ordering::Equal { 85 if let Some((_, next_import_info)) = importables.get(idx + 1) {
86 if key == fst_path(&next_import_info.path) {
86 continue; 87 continue;
87 } 88 }
88 } 89 }
89 90
90 let key = fst_path(&importables[last_batch_start].1.path);
91 builder.insert(key, last_batch_start as u64).unwrap(); 91 builder.insert(key, last_batch_start as u64).unwrap();
92 92
93 last_batch_start = idx + 1; 93 last_batch_start = idx + 1;
@@ -255,12 +255,6 @@ fn fst_path(path: &ImportPath) -> String {
255 s 255 s
256} 256}
257 257
258fn cmp((_, lhs): &(&ItemInNs, &ImportInfo), (_, rhs): &(&ItemInNs, &ImportInfo)) -> Ordering {
259 let lhs_str = fst_path(&lhs.path);
260 let rhs_str = fst_path(&rhs.path);
261 lhs_str.cmp(&rhs_str)
262}
263
264#[derive(Debug, Eq, PartialEq, Hash)] 258#[derive(Debug, Eq, PartialEq, Hash)]
265pub enum ImportKind { 259pub enum ImportKind {
266 Module, 260 Module,