Skip to content

Commit

Permalink
ringbuf: clarify modulus comment.
Browse files Browse the repository at this point in the history
The change that introduced this comment was
automerged, and thus didn't address the comment at
#1624 (comment).
This change just massages the comment a bit to address
that.
  • Loading branch information
dancrossnyc committed Feb 23, 2024
1 parent 534855a commit c53180c
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions lib/ringbuf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,9 @@ impl<T: Copy + PartialEq, const N: usize> Ringbuf<T, { N }> {
let ndx = {
let last_plus_1 = last.wrapping_add(1);
// You're probably wondering why this isn't a remainder operation.
// This is for two reasons:
// 1. None of our target platforms currently have hardware modulus,
// and many of them don't even have hardware divide, making
// remainder quite expensive.
// 2. The code as written here correctly turns usize::MAX into 0 for
// our starting condition. Otherwise we'd have to be cleverer
// about our starting number.
// This is because none of our target platforms currently have
// hardware modulus, and many of them don't even have hardware
// divide, making remainder quite expensive.
if last_plus_1 >= self.buffer.len() {
0
} else {
Expand Down

0 comments on commit c53180c

Please sign in to comment.