From 3b50b0b2b658006c23d21749627e413af5c2aa44 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 24 Jun 2020 16:26:26 +0200 Subject: [PATCH] Use a HashMap instead of Vec This is no longer enforcing stack discipline, so a Vec isn't necessary or helpful --- crates/ra_hir_def/src/body/lower.rs | 17 +++++++++-------- 1 file 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 852d5cda77..3ced648e56 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::{ use super::{ExprSource, PatSource}; use ast::AstChildren; +use rustc_hash::FxHashMap; use std::sync::Arc; pub(crate) struct LowerCtx { @@ -74,7 +75,11 @@ pub(super) fn lower( body_expr: dummy_expr_id(), item_scope: Default::default(), }, - item_trees: vec![(expander.current_file_id, item_tree)], + item_trees: { + let mut map = FxHashMap::default(); + map.insert(expander.current_file_id, item_tree); + map + }, expander, } .collect(params, body) @@ -87,7 +92,7 @@ struct ExprCollector<'a> { body: Body, source_map: BodySourceMap, - item_trees: Vec<(HirFileId, Arc)>, + item_trees: FxHashMap>, } impl ExprCollector<'_> { @@ -541,7 +546,7 @@ impl ExprCollector<'_> { .insert(macro_call, self.expander.current_file_id); let item_tree = self.db.item_tree(self.expander.current_file_id); - self.item_trees.push((self.expander.current_file_id, item_tree)); + self.item_trees.insert(self.expander.current_file_id, item_tree); let id = self.collect_expr(expansion); self.expander.exit(self.db, mark); id @@ -557,11 +562,7 @@ impl ExprCollector<'_> { } fn find_inner_item(&self, id: AstId) -> FileItemTreeId { - let index = - self.item_trees.iter().position(|(file, _)| *file == id.file_id).unwrap_or_else(|| { - panic!("couldn't find item tree for file {:?}", id.file_id); - }); - let tree = &self.item_trees[index].1; + let tree = &self.item_trees[&id.file_id]; // FIXME: This probably breaks with `use` items, since they produce multiple item tree nodes