From d4ddec2bdfc0766782a662b87e1456a9041e8182 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 24 Jun 2020 16:14:58 +0200 Subject: Shrink arenas after building ItemTree --- crates/ra_hir_def/src/item_tree.rs | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'crates/ra_hir_def') diff --git a/crates/ra_hir_def/src/item_tree.rs b/crates/ra_hir_def/src/item_tree.rs index 5155b6111..31f3c4bd8 100644 --- a/crates/ra_hir_def/src/item_tree.rs +++ b/crates/ra_hir_def/src/item_tree.rs @@ -184,6 +184,7 @@ impl ItemTree { if let Some(attrs) = top_attrs { item_tree.attrs.insert(AttrOwner::TopLevel, attrs); } + item_tree.shrink_to_fit(); Arc::new(item_tree) } @@ -196,6 +197,51 @@ impl ItemTree { } } + fn shrink_to_fit(&mut self) { + if let Some(data) = &mut self.data { + let ItemTreeData { + imports, + extern_crates, + functions, + structs, + fields, + unions, + enums, + variants, + consts, + statics, + traits, + impls, + type_aliases, + mods, + macro_calls, + exprs, + vis, + generics, + } = &mut **data; + + imports.shrink_to_fit(); + extern_crates.shrink_to_fit(); + functions.shrink_to_fit(); + structs.shrink_to_fit(); + fields.shrink_to_fit(); + unions.shrink_to_fit(); + enums.shrink_to_fit(); + variants.shrink_to_fit(); + consts.shrink_to_fit(); + statics.shrink_to_fit(); + traits.shrink_to_fit(); + impls.shrink_to_fit(); + type_aliases.shrink_to_fit(); + mods.shrink_to_fit(); + macro_calls.shrink_to_fit(); + exprs.shrink_to_fit(); + + vis.arena.shrink_to_fit(); + generics.arena.shrink_to_fit(); + } + } + /// Returns an iterator over all items located at the top level of the `HirFileId` this /// `ItemTree` was created from. pub fn top_level_items(&self) -> &[ModItem] { -- cgit v1.2.3