aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-03-31 14:04:54 +0100
committerGitHub <[email protected]>2020-03-31 14:04:54 +0100
commit30466e068b2e77eb67e8d29f97ef139668f79903 (patch)
tree70c885398501a9f21a77c9ba1b7f1c6f0c8ac5c9 /crates
parent2cdeb7363a85081803fca184bb603b8e6a61def3 (diff)
parent7ca5ef67e89241065d328445ed7d361270f4b9de (diff)
Merge #3778
3778: Use more functional programming in ArenaMap::insert r=matklad a=kjeremy I find this more readable and it flattens out the body a little. Others may disagree. Co-authored-by: kjeremy <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_arena/src/map.rs10
1 files changed, 2 insertions, 8 deletions
diff --git a/crates/ra_arena/src/map.rs b/crates/ra_arena/src/map.rs
index 5e764113d..0f33907c0 100644
--- a/crates/ra_arena/src/map.rs
+++ b/crates/ra_arena/src/map.rs
@@ -14,14 +14,8 @@ pub struct ArenaMap<ID, V> {
14impl<T, V> ArenaMap<Idx<T>, V> { 14impl<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 if self.v.capacity() <= idx { 17
18 self.v.reserve(idx + 1 - self.v.capacity()); 18 self.v.resize_with((idx + 1).max(self.v.len()), || None);
19 }
20 if self.v.len() <= idx {
21 while self.v.len() <= idx {
22 self.v.push(None);
23 }
24 }
25 self.v[idx] = Some(t); 19 self.v[idx] = Some(t);
26 } 20 }
27 21