diff options
author | kjeremy <[email protected]> | 2020-03-31 14:02:12 +0100 |
---|---|---|
committer | kjeremy <[email protected]> | 2020-03-31 14:02:12 +0100 |
commit | 7ca5ef67e89241065d328445ed7d361270f4b9de (patch) | |
tree | 446416b55a026ab02b5921f91e67ff6bc4766d04 /crates | |
parent | f633f69e36f0aee2cb77a3436b54aeca9aa0d10e (diff) |
Use resize_with
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_arena/src/map.rs | 3 |
1 files changed, 1 insertions, 2 deletions
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<T, V> ArenaMap<Idx<T>, V> { | |||
15 | pub fn insert(&mut self, id: Idx<T>, t: V) { | 15 | pub fn insert(&mut self, id: Idx<T>, t: V) { |
16 | let idx = Self::to_idx(id); | 16 | let idx = Self::to_idx(id); |
17 | 17 | ||
18 | let fill = (idx + 1).saturating_sub(self.v.len()); | 18 | self.v.resize_with((idx + 1).max(self.v.len()), || None); |
19 | self.v.extend(std::iter::repeat_with(|| None).take(fill)); | ||
20 | self.v[idx] = Some(t); | 19 | self.v[idx] = Some(t); |
21 | } | 20 | } |
22 | 21 | ||