Skip to content

Commit adcf18e

Browse files
Add GenericParams::shrink_to_fit
Reduces memory usage by over 10 MB
1 parent 24e876b commit adcf18e

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

crates/hir_def/src/generics.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ impl GenericParams {
218218
GenericDefId::EnumVariantId(_) | GenericDefId::ConstId(_) => FileId(!0).into(),
219219
};
220220

221+
generics.shrink_to_fit();
221222
(generics, InFile::new(file_id, sm))
222223
}
223224

@@ -371,6 +372,14 @@ impl GenericParams {
371372
});
372373
}
373374

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+
374383
pub fn find_type_by_name(&self, name: &Name) -> Option<LocalTypeParamId> {
375384
self.types
376385
.iter()

crates/hir_def/src/item_tree/lower.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,7 @@ impl Ctx {
739739
}
740740
}
741741

742+
generics.shrink_to_fit();
742743
self.data().generics.alloc(generics)
743744
}
744745

0 commit comments

Comments
 (0)