Add GenericParams::shrink_to_fit

Reduces memory usage by over 10 MB
This commit is contained in:
Jonas Schievink 2021-04-05 03:32:43 +02:00
parent 24e876b52e
commit adcf18e27d
2 changed files with 10 additions and 0 deletions

View File

@ -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<LocalTypeParamId> {
self.types
.iter()

View File

@ -739,6 +739,7 @@ impl Ctx {
}
}
generics.shrink_to_fit();
self.data().generics.alloc(generics)
}