diff options
author | Jonas Schievink <[email protected]> | 2021-04-03 22:45:27 +0100 |
---|---|---|
committer | Jonas Schievink <[email protected]> | 2021-04-03 22:45:27 +0100 |
commit | d1bce6070def3b4d5045c3fc4bb66904d50d0a40 (patch) | |
tree | f671f0e97d91f9392f90911ebcb62df8eea958ea /crates/hir_def | |
parent | b78f1a0a4d90276c7bd99bd0e5ac6959578be76a (diff) |
Use shrink_to_fit to reduce DefMap sizes
Diffstat (limited to 'crates/hir_def')
-rw-r--r-- | crates/hir_def/src/item_scope.rs | 11 | ||||
-rw-r--r-- | crates/hir_def/src/nameres.rs | 11 | ||||
-rw-r--r-- | crates/hir_def/src/nameres/collector.rs | 4 |
3 files changed, 25 insertions, 1 deletions
diff --git a/crates/hir_def/src/item_scope.rs b/crates/hir_def/src/item_scope.rs index f3ebe7c72..4ddfd9ee6 100644 --- a/crates/hir_def/src/item_scope.rs +++ b/crates/hir_def/src/item_scope.rs | |||
@@ -285,6 +285,17 @@ impl ItemScope { | |||
285 | buf.push('\n'); | 285 | buf.push('\n'); |
286 | } | 286 | } |
287 | } | 287 | } |
288 | |||
289 | pub(crate) fn shrink_to_fit(&mut self) { | ||
290 | self.types.shrink_to_fit(); | ||
291 | self.values.shrink_to_fit(); | ||
292 | self.macros.shrink_to_fit(); | ||
293 | self.unresolved.shrink_to_fit(); | ||
294 | self.defs.shrink_to_fit(); | ||
295 | self.impls.shrink_to_fit(); | ||
296 | self.unnamed_trait_imports.shrink_to_fit(); | ||
297 | self.legacy_macros.shrink_to_fit(); | ||
298 | } | ||
288 | } | 299 | } |
289 | 300 | ||
290 | impl PerNs { | 301 | impl PerNs { |
diff --git a/crates/hir_def/src/nameres.rs b/crates/hir_def/src/nameres.rs index 9e8e4e9ec..6a09ad420 100644 --- a/crates/hir_def/src/nameres.rs +++ b/crates/hir_def/src/nameres.rs | |||
@@ -409,6 +409,17 @@ impl DefMap { | |||
409 | } | 409 | } |
410 | } | 410 | } |
411 | } | 411 | } |
412 | |||
413 | fn shrink_to_fit(&mut self) { | ||
414 | self.extern_prelude.shrink_to_fit(); | ||
415 | self.exported_proc_macros.shrink_to_fit(); | ||
416 | self.diagnostics.shrink_to_fit(); | ||
417 | self.modules.shrink_to_fit(); | ||
418 | for (_, module) in self.modules.iter_mut() { | ||
419 | module.children.shrink_to_fit(); | ||
420 | module.scope.shrink_to_fit(); | ||
421 | } | ||
422 | } | ||
412 | } | 423 | } |
413 | 424 | ||
414 | impl ModuleData { | 425 | impl ModuleData { |
diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index c2e445b68..4ddc791ce 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs | |||
@@ -109,7 +109,9 @@ pub(super) fn collect_defs( | |||
109 | } | 109 | } |
110 | } | 110 | } |
111 | collector.collect(); | 111 | collector.collect(); |
112 | collector.finish() | 112 | let mut def_map = collector.finish(); |
113 | def_map.shrink_to_fit(); | ||
114 | def_map | ||
113 | } | 115 | } |
114 | 116 | ||
115 | #[derive(Copy, Clone, Debug, Eq, PartialEq)] | 117 | #[derive(Copy, Clone, Debug, Eq, PartialEq)] |