Shrink arenas after building ItemTree
This commit is contained in:
parent
94169ee504
commit
d4ddec2bdf
@ -116,6 +116,9 @@ pub fn iter(
|
||||
) -> impl Iterator<Item = (Idx<T>, &T)> + ExactSizeIterator + DoubleEndedIterator {
|
||||
self.data.iter().enumerate().map(|(idx, value)| (Idx::from_raw(RawId(idx as u32)), value))
|
||||
}
|
||||
pub fn shrink_to_fit(&mut self) {
|
||||
self.data.shrink_to_fit();
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Default for Arena<T> {
|
||||
|
@ -184,6 +184,7 @@ pub fn item_tree_query(db: &dyn DefDatabase, file_id: HirFileId) -> Arc<ItemTree
|
||||
if let Some(attrs) = top_attrs {
|
||||
item_tree.attrs.insert(AttrOwner::TopLevel, attrs);
|
||||
}
|
||||
item_tree.shrink_to_fit();
|
||||
Arc::new(item_tree)
|
||||
}
|
||||
|
||||
@ -196,6 +197,51 @@ fn empty() -> Self {
|
||||
}
|
||||
}
|
||||
|
||||
fn shrink_to_fit(&mut self) {
|
||||
if let Some(data) = &mut self.data {
|
||||
let ItemTreeData {
|
||||
imports,
|
||||
extern_crates,
|
||||
functions,
|
||||
structs,
|
||||
fields,
|
||||
unions,
|
||||
enums,
|
||||
variants,
|
||||
consts,
|
||||
statics,
|
||||
traits,
|
||||
impls,
|
||||
type_aliases,
|
||||
mods,
|
||||
macro_calls,
|
||||
exprs,
|
||||
vis,
|
||||
generics,
|
||||
} = &mut **data;
|
||||
|
||||
imports.shrink_to_fit();
|
||||
extern_crates.shrink_to_fit();
|
||||
functions.shrink_to_fit();
|
||||
structs.shrink_to_fit();
|
||||
fields.shrink_to_fit();
|
||||
unions.shrink_to_fit();
|
||||
enums.shrink_to_fit();
|
||||
variants.shrink_to_fit();
|
||||
consts.shrink_to_fit();
|
||||
statics.shrink_to_fit();
|
||||
traits.shrink_to_fit();
|
||||
impls.shrink_to_fit();
|
||||
type_aliases.shrink_to_fit();
|
||||
mods.shrink_to_fit();
|
||||
macro_calls.shrink_to_fit();
|
||||
exprs.shrink_to_fit();
|
||||
|
||||
vis.arena.shrink_to_fit();
|
||||
generics.arena.shrink_to_fit();
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns an iterator over all items located at the top level of the `HirFileId` this
|
||||
/// `ItemTree` was created from.
|
||||
pub fn top_level_items(&self) -> &[ModItem] {
|
||||
|
Loading…
Reference in New Issue
Block a user