Skip to content

Commit c397252

Browse files
committed
Use more functional programming in ArenaMap::insert
I find this more readable and it flattens out the body a little.
1 parent 6f0d8db commit c397252

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

crates/ra_arena/src/map.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ impl<T, V> ArenaMap<Idx<T>, V> {
1717
if self.v.capacity() <= idx {
1818
self.v.reserve(idx + 1 - self.v.capacity());
1919
}
20-
if self.v.len() <= idx {
21-
while self.v.len() <= idx {
22-
self.v.push(None);
23-
}
24-
}
20+
21+
let fill = (idx + 1).saturating_sub(self.v.len());
22+
self.v.extend(std::iter::repeat_with(|| None).take(fill));
2523
self.v[idx] = Some(t);
2624
}
2725

0 commit comments

Comments
 (0)