diff options
author | Jonas Schievink <[email protected]> | 2021-04-05 02:32:43 +0100 |
---|---|---|
committer | Jonas Schievink <[email protected]> | 2021-04-05 02:32:43 +0100 |
commit | adcf18e27dc04b60fede859f3d6c22b99d4fd513 (patch) | |
tree | e2c8e86b17a89cc9e2f6ebd874d8cc30fe5f4e64 /crates/hir_def/src | |
parent | 24e876b52ed76710593895bc37bb8ed303075193 (diff) |
Add `GenericParams::shrink_to_fit`
Reduces memory usage by over 10 MB
Diffstat (limited to 'crates/hir_def/src')
-rw-r--r-- | crates/hir_def/src/generics.rs | 9 | ||||
-rw-r--r-- | crates/hir_def/src/item_tree/lower.rs | 1 |
2 files changed, 10 insertions, 0 deletions
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 { | |||
218 | GenericDefId::EnumVariantId(_) | GenericDefId::ConstId(_) => FileId(!0).into(), | 218 | GenericDefId::EnumVariantId(_) | GenericDefId::ConstId(_) => FileId(!0).into(), |
219 | }; | 219 | }; |
220 | 220 | ||
221 | generics.shrink_to_fit(); | ||
221 | (generics, InFile::new(file_id, sm)) | 222 | (generics, InFile::new(file_id, sm)) |
222 | } | 223 | } |
223 | 224 | ||
@@ -371,6 +372,14 @@ impl GenericParams { | |||
371 | }); | 372 | }); |
372 | } | 373 | } |
373 | 374 | ||
375 | pub(crate) fn shrink_to_fit(&mut self) { | ||
376 | let Self { consts, lifetimes, types, where_predicates } = self; | ||
377 | consts.shrink_to_fit(); | ||
378 | lifetimes.shrink_to_fit(); | ||
379 | types.shrink_to_fit(); | ||
380 | where_predicates.shrink_to_fit(); | ||
381 | } | ||
382 | |||
374 | pub fn find_type_by_name(&self, name: &Name) -> Option<LocalTypeParamId> { | 383 | pub fn find_type_by_name(&self, name: &Name) -> Option<LocalTypeParamId> { |
375 | self.types | 384 | self.types |
376 | .iter() | 385 | .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 { | |||
739 | } | 739 | } |
740 | } | 740 | } |
741 | 741 | ||
742 | generics.shrink_to_fit(); | ||
742 | self.data().generics.alloc(generics) | 743 | self.data().generics.alloc(generics) |
743 | } | 744 | } |
744 | 745 | ||