aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/hir_def/src/item_scope.rs11
-rw-r--r--crates/hir_def/src/nameres.rs11
-rw-r--r--crates/hir_def/src/nameres/collector.rs4
-rw-r--r--lib/arena/src/lib.rs23
4 files changed, 48 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
290impl PerNs { 301impl 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
414impl ModuleData { 425impl 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)]
diff --git a/lib/arena/src/lib.rs b/lib/arena/src/lib.rs
index 230a50291..bce15c867 100644
--- a/lib/arena/src/lib.rs
+++ b/lib/arena/src/lib.rs
@@ -194,6 +194,29 @@ impl<T> Arena<T> {
194 self.data.iter().enumerate().map(|(idx, value)| (Idx::from_raw(RawIdx(idx as u32)), value)) 194 self.data.iter().enumerate().map(|(idx, value)| (Idx::from_raw(RawIdx(idx as u32)), value))
195 } 195 }
196 196
197 /// Returns an iterator over the arena’s mutable elements.
198 ///
199 /// ```
200 /// let mut arena = la_arena::Arena::new();
201 /// let idx1 = arena.alloc(20);
202 ///
203 /// assert_eq!(arena[idx1], 20);
204 ///
205 /// let mut iterator = arena.iter_mut();
206 /// *iterator.next().unwrap().1 = 10;
207 /// drop(iterator);
208 ///
209 /// assert_eq!(arena[idx1], 10);
210 /// ```
211 pub fn iter_mut(
212 &mut self,
213 ) -> impl Iterator<Item = (Idx<T>, &mut T)> + ExactSizeIterator + DoubleEndedIterator {
214 self.data
215 .iter_mut()
216 .enumerate()
217 .map(|(idx, value)| (Idx::from_raw(RawIdx(idx as u32)), value))
218 }
219
197 /// Reallocates the arena to make it take up as little space as possible. 220 /// Reallocates the arena to make it take up as little space as possible.
198 pub fn shrink_to_fit(&mut self) { 221 pub fn shrink_to_fit(&mut self) {
199 self.data.shrink_to_fit(); 222 self.data.shrink_to_fit();