diff options
author | Jonas Schievink <[email protected]> | 2020-06-24 15:14:58 +0100 |
---|---|---|
committer | Jonas Schievink <[email protected]> | 2020-06-24 15:54:21 +0100 |
commit | d4ddec2bdfc0766782a662b87e1456a9041e8182 (patch) | |
tree | 1e7e758e14b609fcec6aae19bd5001290286ec47 | |
parent | 94169ee504bf1a5e59530c1ab1f5f5550ae45914 (diff) |
Shrink arenas after building ItemTree
-rw-r--r-- | crates/ra_arena/src/lib.rs | 3 | ||||
-rw-r--r-- | crates/ra_hir_def/src/item_tree.rs | 46 |
2 files changed, 49 insertions, 0 deletions
diff --git a/crates/ra_arena/src/lib.rs b/crates/ra_arena/src/lib.rs index 441fbb3cb..3169aa5b8 100644 --- a/crates/ra_arena/src/lib.rs +++ b/crates/ra_arena/src/lib.rs | |||
@@ -116,6 +116,9 @@ impl<T> Arena<T> { | |||
116 | ) -> impl Iterator<Item = (Idx<T>, &T)> + ExactSizeIterator + DoubleEndedIterator { | 116 | ) -> impl Iterator<Item = (Idx<T>, &T)> + ExactSizeIterator + DoubleEndedIterator { |
117 | self.data.iter().enumerate().map(|(idx, value)| (Idx::from_raw(RawId(idx as u32)), value)) | 117 | self.data.iter().enumerate().map(|(idx, value)| (Idx::from_raw(RawId(idx as u32)), value)) |
118 | } | 118 | } |
119 | pub fn shrink_to_fit(&mut self) { | ||
120 | self.data.shrink_to_fit(); | ||
121 | } | ||
119 | } | 122 | } |
120 | 123 | ||
121 | impl<T> Default for Arena<T> { | 124 | impl<T> Default for Arena<T> { |
diff --git a/crates/ra_hir_def/src/item_tree.rs b/crates/ra_hir_def/src/item_tree.rs index 5155b6111..31f3c4bd8 100644 --- a/crates/ra_hir_def/src/item_tree.rs +++ b/crates/ra_hir_def/src/item_tree.rs | |||
@@ -184,6 +184,7 @@ impl ItemTree { | |||
184 | if let Some(attrs) = top_attrs { | 184 | if let Some(attrs) = top_attrs { |
185 | item_tree.attrs.insert(AttrOwner::TopLevel, attrs); | 185 | item_tree.attrs.insert(AttrOwner::TopLevel, attrs); |
186 | } | 186 | } |
187 | item_tree.shrink_to_fit(); | ||
187 | Arc::new(item_tree) | 188 | Arc::new(item_tree) |
188 | } | 189 | } |
189 | 190 | ||
@@ -196,6 +197,51 @@ impl ItemTree { | |||
196 | } | 197 | } |
197 | } | 198 | } |
198 | 199 | ||
200 | fn shrink_to_fit(&mut self) { | ||
201 | if let Some(data) = &mut self.data { | ||
202 | let ItemTreeData { | ||
203 | imports, | ||
204 | extern_crates, | ||
205 | functions, | ||
206 | structs, | ||
207 | fields, | ||
208 | unions, | ||
209 | enums, | ||
210 | variants, | ||
211 | consts, | ||
212 | statics, | ||
213 | traits, | ||
214 | impls, | ||
215 | type_aliases, | ||
216 | mods, | ||
217 | macro_calls, | ||
218 | exprs, | ||
219 | vis, | ||
220 | generics, | ||
221 | } = &mut **data; | ||
222 | |||
223 | imports.shrink_to_fit(); | ||
224 | extern_crates.shrink_to_fit(); | ||
225 | functions.shrink_to_fit(); | ||
226 | structs.shrink_to_fit(); | ||
227 | fields.shrink_to_fit(); | ||
228 | unions.shrink_to_fit(); | ||
229 | enums.shrink_to_fit(); | ||
230 | variants.shrink_to_fit(); | ||
231 | consts.shrink_to_fit(); | ||
232 | statics.shrink_to_fit(); | ||
233 | traits.shrink_to_fit(); | ||
234 | impls.shrink_to_fit(); | ||
235 | type_aliases.shrink_to_fit(); | ||
236 | mods.shrink_to_fit(); | ||
237 | macro_calls.shrink_to_fit(); | ||
238 | exprs.shrink_to_fit(); | ||
239 | |||
240 | vis.arena.shrink_to_fit(); | ||
241 | generics.arena.shrink_to_fit(); | ||
242 | } | ||
243 | } | ||
244 | |||
199 | /// Returns an iterator over all items located at the top level of the `HirFileId` this | 245 | /// Returns an iterator over all items located at the top level of the `HirFileId` this |
200 | /// `ItemTree` was created from. | 246 | /// `ItemTree` was created from. |
201 | pub fn top_level_items(&self) -> &[ModItem] { | 247 | pub fn top_level_items(&self) -> &[ModItem] { |