Skip to content

Commit 690cd95

Browse files
Reduce fst_path calls
1 parent 3aaf07b commit 690cd95

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

crates/hir_def/src/import_map.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! A map of all publicly exported items in a crate.
22
3-
use std::{cmp::Ordering, fmt, hash::BuildHasherDefault, sync::Arc};
3+
use std::{fmt, hash::BuildHasherDefault, sync::Arc};
44

55
use base_db::CrateId;
66
use fst::{self, Streamer};
@@ -73,21 +73,21 @@ impl ImportMap {
7373
let mut import_map = collect_import_map(db, krate);
7474

7575
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));
7777

7878
// Build the FST, taking care not to insert duplicate values.
7979

8080
let mut builder = fst::MapBuilder::memory();
8181
let mut last_batch_start = 0;
8282

8383
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) {
8687
continue;
8788
}
8889
}
8990

90-
let key = fst_path(&importables[last_batch_start].1.path);
9191
builder.insert(key, last_batch_start as u64).unwrap();
9292

9393
last_batch_start = idx + 1;
@@ -255,12 +255,6 @@ fn fst_path(path: &ImportPath) -> String {
255255
s
256256
}
257257

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-
264258
#[derive(Debug, Eq, PartialEq, Hash)]
265259
pub enum ImportKind {
266260
Module,

0 commit comments

Comments
 (0)