Skip to content

Commit

Permalink
Use get_unchecked_mut() for incrementing signal strength counters
Browse files Browse the repository at this point in the history
  • Loading branch information
BramOtte committed Dec 12, 2023
1 parent 9d7c5f4 commit 7c59fd2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions crates/core/src/redpiler/backend/direct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,15 @@ impl DirectBackend {
} else {
&mut update_ref.default_inputs
};
inputs[old_power.saturating_sub(distance) as usize] -= 1;
inputs[new_power.saturating_sub(distance) as usize] += 1;

let old_power = old_power.saturating_sub(distance);
let new_power = new_power.saturating_sub(distance);

// Safety: signal strength is never larger than 15
unsafe {
*inputs.get_unchecked_mut(old_power as usize) -= 1;
*inputs.get_unchecked_mut(new_power as usize) += 1;
}

update_node(&mut self.scheduler, &mut self.nodes, update);
}
Expand Down

0 comments on commit 7c59fd2

Please sign in to comment.