From 7ca5ef67e89241065d328445ed7d361270f4b9de Mon Sep 17 00:00:00 2001 From: kjeremy Date: Tue, 31 Mar 2020 09:02:12 -0400 Subject: Use resize_with --- crates/ra_arena/src/map.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'crates') diff --git a/crates/ra_arena/src/map.rs b/crates/ra_arena/src/map.rs index e4ddbad42..0f33907c0 100644 --- a/crates/ra_arena/src/map.rs +++ b/crates/ra_arena/src/map.rs @@ -15,8 +15,7 @@ impl ArenaMap, V> { pub fn insert(&mut self, id: Idx, t: V) { let idx = Self::to_idx(id); - let fill = (idx + 1).saturating_sub(self.v.len()); - self.v.extend(std::iter::repeat_with(|| None).take(fill)); + self.v.resize_with((idx + 1).max(self.v.len()), || None); self.v[idx] = Some(t); } -- cgit v1.2.3