From 690cd953273317ee4f3eaefd95bbd3538e929522 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Fri, 11 Jun 2021 00:10:09 +0300 Subject: Reduce fst_path calls --- crates/hir_def/src/import_map.rs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'crates/hir_def/src') 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 @@ //! A map of all publicly exported items in a crate. -use std::{cmp::Ordering, fmt, hash::BuildHasherDefault, sync::Arc}; +use std::{fmt, hash::BuildHasherDefault, sync::Arc}; use base_db::CrateId; use fst::{self, Streamer}; @@ -73,7 +73,7 @@ impl ImportMap { let mut import_map = collect_import_map(db, krate); let mut importables = import_map.map.iter().collect::>(); - importables.sort_by(cmp); + importables.sort_by_cached_key(|(_, import_info)| fst_path(&import_info.path)); // Build the FST, taking care not to insert duplicate values. @@ -81,13 +81,13 @@ impl ImportMap { let mut last_batch_start = 0; for idx in 0..importables.len() { - if let Some(next_item) = importables.get(idx + 1) { - if cmp(&importables[last_batch_start], next_item) == Ordering::Equal { + let key = fst_path(&importables[last_batch_start].1.path); + if let Some((_, next_import_info)) = importables.get(idx + 1) { + if key == fst_path(&next_import_info.path) { continue; } } - let key = fst_path(&importables[last_batch_start].1.path); builder.insert(key, last_batch_start as u64).unwrap(); last_batch_start = idx + 1; @@ -255,12 +255,6 @@ fn fst_path(path: &ImportPath) -> String { s } -fn cmp((_, lhs): &(&ItemInNs, &ImportInfo), (_, rhs): &(&ItemInNs, &ImportInfo)) -> Ordering { - let lhs_str = fst_path(&lhs.path); - let rhs_str = fst_path(&rhs.path); - lhs_str.cmp(&rhs_str) -} - #[derive(Debug, Eq, PartialEq, Hash)] pub enum ImportKind { Module, -- cgit v1.2.3