|
1 | 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 | 5 | use base_db::CrateId;
|
6 | 6 | use fst::{self, Streamer};
|
@@ -73,21 +73,21 @@ impl ImportMap {
|
73 | 73 | let mut import_map = collect_import_map(db, krate);
|
74 | 74 |
|
75 | 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 | 78 | // Build the FST, taking care not to insert duplicate values.
|
79 | 79 |
|
80 | 80 | let mut builder = fst::MapBuilder::memory();
|
81 | 81 | let mut last_batch_start = 0;
|
82 | 82 |
|
83 | 83 | for idx in 0..importables.len() {
|
84 |
| - if let Some(next_item) = importables.get(idx + 1) { |
85 |
| - if cmp(&importables[last_batch_start], next_item) == Ordering::Equal { |
| 84 | + let key = fst_path(&importables[last_batch_start].1.path); |
| 85 | + if let Some((_, next_import_info)) = importables.get(idx + 1) { |
| 86 | + if key == fst_path(&next_import_info.path) { |
86 | 87 | continue;
|
87 | 88 | }
|
88 | 89 | }
|
89 | 90 |
|
90 |
| - let key = fst_path(&importables[last_batch_start].1.path); |
91 | 91 | builder.insert(key, last_batch_start as u64).unwrap();
|
92 | 92 |
|
93 | 93 | last_batch_start = idx + 1;
|
@@ -255,12 +255,6 @@ fn fst_path(path: &ImportPath) -> String {
|
255 | 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 | 258 | #[derive(Debug, Eq, PartialEq, Hash)]
|
265 | 259 | pub enum ImportKind {
|
266 | 260 | Module,
|
|
0 commit comments