aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkjeremy <[email protected]>2020-03-30 21:15:28 +0100
committerkjeremy <[email protected]>2020-03-30 21:15:28 +0100
commitc39725212c332bdc0914ca17947c8251b3b1e006 (patch)
treea97cc77f3b01045fffe08016850c8cc90f707788
parent6f0d8db529478ce41b429f06708fa600a97c2151 (diff)
Use more functional programming in ArenaMap::insert
I find this more readable and it flattens out the body a little.
-rw-r--r--crates/ra_arena/src/map.rs8
1 files changed, 3 insertions, 5 deletions
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<T, V> ArenaMap<Idx<T>, V> {
17 if self.v.capacity() <= idx { 17 if self.v.capacity() <= idx {
18 self.v.reserve(idx + 1 - self.v.capacity()); 18 self.v.reserve(idx + 1 - self.v.capacity());
19 } 19 }
20 if self.v.len() <= idx { 20
21 while self.v.len() <= idx { 21 let fill = (idx + 1).saturating_sub(self.v.len());
22 self.v.push(None); 22 self.v.extend(std::iter::repeat_with(|| None).take(fill));
23 }
24 }
25 self.v[idx] = Some(t); 23 self.v[idx] = Some(t);
26 } 24 }
27 25