aboutsummaryrefslogtreecommitdiff
path: root/lib/arena/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-04-03 22:47:39 +0100
committerGitHub <[email protected]>2021-04-03 22:47:39 +0100
commita3dc04905b4c1a88ece9cc252bfbf9e321f29428 (patch)
treef671f0e97d91f9392f90911ebcb62df8eea958ea /lib/arena/src
parentb78f1a0a4d90276c7bd99bd0e5ac6959578be76a (diff)
parentd1bce6070def3b4d5045c3fc4bb66904d50d0a40 (diff)
Merge #8318
8318: Use shrink_to_fit to reduce DefMap sizes r=jonas-schievink a=jonas-schievink Especially `block_def_map` can overallocate when there's not a lot of items in the `DefMap`. This saves around 10 MB during analysis-stats. Not too much, but a cheap win. bors r+ Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'lib/arena/src')
-rw-r--r--lib/arena/src/lib.rs23
1 files changed, 23 insertions, 0 deletions
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();