Skip to content

Commit

Permalink
Make ensure_len use resize_with
Browse files Browse the repository at this point in the history
  • Loading branch information
jujhar16 authored and XVilka committed Apr 7, 2023
1 parent b9bf9ee commit 4556977
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions src/matrix_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -897,12 +897,7 @@ fn extend_lower_triangular_matrix<T: Default>(

/// Grow a Vec by appending the type's default value until the `size` is reached.
fn ensure_len<T: Default>(v: &mut Vec<T>, size: usize) {
if let Some(n) = size.checked_sub(v.len()) {
v.reserve(n);
for _ in 0..n {
v.push(T::default());
}
}
v.resize_with(size, T::default);
}

#[derive(Debug, Clone)]
Expand Down

0 comments on commit 4556977

Please sign in to comment.