]> git.lizzy.rs Git - rust.git/commitdiff
Simplify
authorLukas Wirth <lukastw97@gmail.com>
Tue, 21 Dec 2021 17:25:50 +0000 (18:25 +0100)
committerLukas Wirth <lukastw97@gmail.com>
Tue, 21 Dec 2021 17:28:04 +0000 (18:28 +0100)
crates/hir_def/src/import_map.rs
crates/ide_completion/src/context.rs

index 27a05b87c1d0d942ee4581a85ac158edd34dc5b0..5e91a3df0a2b84d052b2747b90caad62834e8b54 100644 (file)
@@ -72,8 +72,12 @@ pub fn import_map_query(db: &dyn DefDatabase, krate: CrateId) -> Arc<Self> {
 
         let mut import_map = collect_import_map(db, krate);
 
-        let mut importables = import_map.map.iter().collect::<Vec<_>>();
-        importables.sort_by_cached_key(|(_, import_info)| fst_path(&import_info.path));
+        let mut importables = import_map
+            .map
+            .iter()
+            .map(|(item, info)| (item, fst_path(&info.path)))
+            .collect::<Vec<_>>();
+        importables.sort_by(|(_, fst_path), (_, fst_path2)| fst_path.cmp(fst_path2));
 
         // Build the FST, taking care not to insert duplicate values.
 
@@ -81,20 +85,20 @@ pub fn import_map_query(db: &dyn DefDatabase, krate: CrateId) -> Arc<Self> {
         let mut last_batch_start = 0;
 
         for idx in 0..importables.len() {
-            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) {
+            let key = &importables[last_batch_start].1;
+            if let Some((_, fst_path)) = importables.get(idx + 1) {
+                if key == fst_path {
                     continue;
                 }
             }
 
-            builder.insert(key, last_batch_start as u64).unwrap();
+            let _ = builder.insert(key, last_batch_start as u64);
 
             last_batch_start = idx + 1;
         }
 
-        import_map.fst = fst::Map::new(builder.into_inner().unwrap()).unwrap();
-        import_map.importables = importables.iter().map(|(item, _)| **item).collect();
+        import_map.fst = builder.into_map();
+        import_map.importables = importables.iter().map(|&(&item, _)| item).collect();
 
         Arc::new(import_map)
     }
index d0ed98898986cc59065acab67e088981662dfccc..2a1891c76b238eb0410ac2c4267caf9366326927 100644 (file)
@@ -302,6 +302,7 @@ pub(crate) fn is_immediately_after_macro_bang(&self) -> bool {
 
     /// A version of [`SemanticsScope::process_all_names`] that filters out `#[doc(hidden)]` items.
     pub(crate) fn process_all_names(&self, f: &mut dyn FnMut(Name, ScopeDef)) {
+        let _p = profile::span("CompletionContext::process_all_names");
         self.scope.process_all_names(&mut |name, def| {
             if self.is_scope_def_hidden(def) {
                 return;
@@ -422,6 +423,7 @@ fn expand_and_fill(
         mut offset: TextSize,
         mut fake_ident_token: SyntaxToken,
     ) {
+        let _p = profile::span("CompletionContext::expand_and_fill");
         loop {
             // Expand attributes
             if let (Some(actual_item), Some(item_with_fake_ident)) = (