Skip to content

Commit

Permalink
docs: vec cap can't overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Rudxain committed Dec 8, 2024
1 parent 7052646 commit f0f6c51
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/gui/views/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -952,8 +952,15 @@ fn build_action_pkg_commands(
let pkg = &packages[selection.0][selection.1];
let wanted_state = pkg.state.opposite(settings.disable_mode);

// assume 2 actions per user
let mut commands = Vec::with_capacity(device.user_list.len() * 2);
// performance, and fail-fast in case of OOM
let mut commands = Vec::with_capacity(
device
.user_list
.len()
// ~2 actions per user
.checked_mul(2)
.unwrap_or_else(|| unreachable!()),
);

for u in device.user_list.iter().filter(|&&u| {
!u.protected && (packages[u.index][selection.1].selected || settings.multi_user_mode)
Expand Down

0 comments on commit f0f6c51

Please sign in to comment.