mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 15:54:15 +00:00
Use resize_with
This commit is contained in:
parent
f633f69e36
commit
7ca5ef67e8
@ -15,8 +15,7 @@ impl<T, V> ArenaMap<Idx<T>, V> {
|
||||
pub fn insert(&mut self, id: Idx<T>, t: V) {
|
||||
let idx = Self::to_idx(id);
|
||||
|
||||
let fill = (idx + 1).saturating_sub(self.v.len());
|
||||
self.v.extend(std::iter::repeat_with(|| None).take(fill));
|
||||
self.v.resize_with((idx + 1).max(self.v.len()), || None);
|
||||
self.v[idx] = Some(t);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user