aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2021-04-03 22:45:27 +0100
committerJonas Schievink <[email protected]>2021-04-03 22:45:27 +0100
commitd1bce6070def3b4d5045c3fc4bb66904d50d0a40 (patch)
treef671f0e97d91f9392f90911ebcb62df8eea958ea /lib
parentb78f1a0a4d90276c7bd99bd0e5ac6959578be76a (diff)
Use shrink_to_fit to reduce DefMap sizes
Diffstat (limited to 'lib')
-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();