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 <kjeremy@gmail.com>
This commit is contained in:
bors[bot] 2020-03-31 13:04:54 +00:00 committed by GitHub
commit 30466e068b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,14 +14,8 @@ pub struct ArenaMap<ID, V> {
impl<T, V> ArenaMap<Idx<T>, V> {
pub fn insert(&mut self, id: Idx<T>, t: V) {
let idx = Self::to_idx(id);
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);
}
}
self.v.resize_with((idx + 1).max(self.v.len()), || None);
self.v[idx] = Some(t);
}