From adcf18e27dc04b60fede859f3d6c22b99d4fd513 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Mon, 5 Apr 2021 03:32:43 +0200 Subject: Add `GenericParams::shrink_to_fit` Reduces memory usage by over 10 MB --- crates/hir_def/src/generics.rs | 9 +++++++++ crates/hir_def/src/item_tree/lower.rs | 1 + 2 files changed, 10 insertions(+) (limited to 'crates/hir_def/src') diff --git a/crates/hir_def/src/generics.rs b/crates/hir_def/src/generics.rs index e02ac2c2f..d55c189d4 100644 --- a/crates/hir_def/src/generics.rs +++ b/crates/hir_def/src/generics.rs @@ -218,6 +218,7 @@ impl GenericParams { GenericDefId::EnumVariantId(_) | GenericDefId::ConstId(_) => FileId(!0).into(), }; + generics.shrink_to_fit(); (generics, InFile::new(file_id, sm)) } @@ -371,6 +372,14 @@ impl GenericParams { }); } + pub(crate) fn shrink_to_fit(&mut self) { + let Self { consts, lifetimes, types, where_predicates } = self; + consts.shrink_to_fit(); + lifetimes.shrink_to_fit(); + types.shrink_to_fit(); + where_predicates.shrink_to_fit(); + } + pub fn find_type_by_name(&self, name: &Name) -> Option { self.types .iter() diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs index ab7ad8310..0c8112dda 100644 --- a/crates/hir_def/src/item_tree/lower.rs +++ b/crates/hir_def/src/item_tree/lower.rs @@ -739,6 +739,7 @@ impl Ctx { } } + generics.shrink_to_fit(); self.data().generics.alloc(generics) } -- cgit v1.2.3