Use more functional programming in ArenaMap::insert

I find this more readable and it flattens out the body a little.
This commit is contained in:
kjeremy 2020-03-30 16:15:28 -04:00
parent 6f0d8db529
commit c39725212c

View File

@ -17,11 +17,9 @@ pub fn insert(&mut self, id: Idx<T>, t: 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);
}