From d1bce6070def3b4d5045c3fc4bb66904d50d0a40 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Sat, 3 Apr 2021 23:45:27 +0200 Subject: Use shrink_to_fit to reduce DefMap sizes --- crates/hir_def/src/item_scope.rs | 11 +++++++++++ crates/hir_def/src/nameres.rs | 11 +++++++++++ crates/hir_def/src/nameres/collector.rs | 4 +++- 3 files changed, 25 insertions(+), 1 deletion(-) (limited to 'crates/hir_def/src') diff --git a/crates/hir_def/src/item_scope.rs b/crates/hir_def/src/item_scope.rs index f3ebe7c72..4ddfd9ee6 100644 --- a/crates/hir_def/src/item_scope.rs +++ b/crates/hir_def/src/item_scope.rs @@ -285,6 +285,17 @@ impl ItemScope { buf.push('\n'); } } + + pub(crate) fn shrink_to_fit(&mut self) { + self.types.shrink_to_fit(); + self.values.shrink_to_fit(); + self.macros.shrink_to_fit(); + self.unresolved.shrink_to_fit(); + self.defs.shrink_to_fit(); + self.impls.shrink_to_fit(); + self.unnamed_trait_imports.shrink_to_fit(); + self.legacy_macros.shrink_to_fit(); + } } impl PerNs { diff --git a/crates/hir_def/src/nameres.rs b/crates/hir_def/src/nameres.rs index 9e8e4e9ec..6a09ad420 100644 --- a/crates/hir_def/src/nameres.rs +++ b/crates/hir_def/src/nameres.rs @@ -409,6 +409,17 @@ impl DefMap { } } } + + fn shrink_to_fit(&mut self) { + self.extern_prelude.shrink_to_fit(); + self.exported_proc_macros.shrink_to_fit(); + self.diagnostics.shrink_to_fit(); + self.modules.shrink_to_fit(); + for (_, module) in self.modules.iter_mut() { + module.children.shrink_to_fit(); + module.scope.shrink_to_fit(); + } + } } impl ModuleData { diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index c2e445b68..4ddc791ce 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs @@ -109,7 +109,9 @@ pub(super) fn collect_defs( } } collector.collect(); - collector.finish() + let mut def_map = collector.finish(); + def_map.shrink_to_fit(); + def_map } #[derive(Copy, Clone, Debug, Eq, PartialEq)] -- cgit v1.2.3