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:
parent
6f0d8db529
commit
c39725212c
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user