aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2020-06-24 15:26:26 +0100
committerJonas Schievink <[email protected]>2020-06-24 15:54:21 +0100
commit3b50b0b2b658006c23d21749627e413af5c2aa44 (patch)
treecfbe361198096d9dc62bc34c624b84dc470a1dcb /crates/ra_hir_def/src
parent59d4640b644fa12ecc8f5075d92e5c53124e5dd7 (diff)
Use a HashMap instead of Vec
This is no longer enforcing stack discipline, so a Vec isn't necessary or helpful
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r--crates/ra_hir_def/src/body/lower.rs17
1 files changed, 9 insertions, 8 deletions
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs
index 852d5cda7..3ced648e5 100644
--- a/crates/ra_hir_def/src/body/lower.rs
+++ b/crates/ra_hir_def/src/body/lower.rs
@@ -36,6 +36,7 @@ use crate::{
36 36
37use super::{ExprSource, PatSource}; 37use super::{ExprSource, PatSource};
38use ast::AstChildren; 38use ast::AstChildren;
39use rustc_hash::FxHashMap;
39use std::sync::Arc; 40use std::sync::Arc;
40 41
41pub(crate) struct LowerCtx { 42pub(crate) struct LowerCtx {
@@ -74,7 +75,11 @@ pub(super) fn lower(
74 body_expr: dummy_expr_id(), 75 body_expr: dummy_expr_id(),
75 item_scope: Default::default(), 76 item_scope: Default::default(),
76 }, 77 },
77 item_trees: vec![(expander.current_file_id, item_tree)], 78 item_trees: {
79 let mut map = FxHashMap::default();
80 map.insert(expander.current_file_id, item_tree);
81 map
82 },
78 expander, 83 expander,
79 } 84 }
80 .collect(params, body) 85 .collect(params, body)
@@ -87,7 +92,7 @@ struct ExprCollector<'a> {
87 body: Body, 92 body: Body,
88 source_map: BodySourceMap, 93 source_map: BodySourceMap,
89 94
90 item_trees: Vec<(HirFileId, Arc<ItemTree>)>, 95 item_trees: FxHashMap<HirFileId, Arc<ItemTree>>,
91} 96}
92 97
93impl ExprCollector<'_> { 98impl ExprCollector<'_> {
@@ -541,7 +546,7 @@ impl ExprCollector<'_> {
541 .insert(macro_call, self.expander.current_file_id); 546 .insert(macro_call, self.expander.current_file_id);
542 547
543 let item_tree = self.db.item_tree(self.expander.current_file_id); 548 let item_tree = self.db.item_tree(self.expander.current_file_id);
544 self.item_trees.push((self.expander.current_file_id, item_tree)); 549 self.item_trees.insert(self.expander.current_file_id, item_tree);
545 let id = self.collect_expr(expansion); 550 let id = self.collect_expr(expansion);
546 self.expander.exit(self.db, mark); 551 self.expander.exit(self.db, mark);
547 id 552 id
@@ -557,11 +562,7 @@ impl ExprCollector<'_> {
557 } 562 }
558 563
559 fn find_inner_item<S: ItemTreeNode>(&self, id: AstId<ast::ModuleItem>) -> FileItemTreeId<S> { 564 fn find_inner_item<S: ItemTreeNode>(&self, id: AstId<ast::ModuleItem>) -> FileItemTreeId<S> {
560 let index = 565 let tree = &self.item_trees[&id.file_id];
561 self.item_trees.iter().position(|(file, _)| *file == id.file_id).unwrap_or_else(|| {
562 panic!("couldn't find item tree for file {:?}", id.file_id);
563 });
564 let tree = &self.item_trees[index].1;
565 566
566 // FIXME: This probably breaks with `use` items, since they produce multiple item tree nodes 567 // FIXME: This probably breaks with `use` items, since they produce multiple item tree nodes
567 568