Skip to content

Commit 30466e0

Browse files
bors[bot]kjeremy
andauthored
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]>
2 parents 2cdeb73 + 7ca5ef6 commit 30466e0

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

crates/ra_arena/src/map.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,8 @@ pub struct ArenaMap<ID, V> {
1414
impl<T, V> ArenaMap<Idx<T>, V> {
1515
pub fn insert(&mut self, id: Idx<T>, t: V) {
1616
let idx = Self::to_idx(id);
17-
if self.v.capacity() <= idx {
18-
self.v.reserve(idx + 1 - self.v.capacity());
19-
}
20-
if self.v.len() <= idx {
21-
while self.v.len() <= idx {
22-
self.v.push(None);
23-
}
24-
}
17+
18+
self.v.resize_with((idx + 1).max(self.v.len()), || None);
2519
self.v[idx] = Some(t);
2620
}
2721

0 commit comments

Comments
 (0)