diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/hir_def/src/import_map.rs | 16 |
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 | ||
3 | use std::{cmp::Ordering, fmt, hash::BuildHasherDefault, sync::Arc}; | 3 | use std::{fmt, hash::BuildHasherDefault, sync::Arc}; |
4 | 4 | ||
5 | use base_db::CrateId; | 5 | use base_db::CrateId; |
6 | use fst::{self, Streamer}; | 6 | use 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 | ||
258 | fn 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)] |
265 | pub enum ImportKind { | 259 | pub enum ImportKind { |
266 | Module, | 260 | Module, |