From c39725212c332bdc0914ca17947c8251b3b1e006 Mon Sep 17 00:00:00 2001 From: kjeremy Date: Mon, 30 Mar 2020 16:15:28 -0400 Subject: Use more functional programming in ArenaMap::insert I find this more readable and it flattens out the body a little. --- crates/ra_arena/src/map.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'crates/ra_arena/src') diff --git a/crates/ra_arena/src/map.rs b/crates/ra_arena/src/map.rs index 5e764113d..b9521c342 100644 --- a/crates/ra_arena/src/map.rs +++ b/crates/ra_arena/src/map.rs @@ -17,11 +17,9 @@ impl ArenaMap, V> { if self.v.capacity() <= idx { self.v.reserve(idx + 1 - self.v.capacity()); } - if self.v.len() <= idx { - while self.v.len() <= idx { - self.v.push(None); - } - } + + let fill = (idx + 1).saturating_sub(self.v.len()); + self.v.extend(std::iter::repeat_with(|| None).take(fill)); self.v[idx] = Some(t); } -- cgit v1.2.3