Skip to content

Commit 66fb024

Browse files
committed
deque: avoid expensive modulo operation.
1 parent 96631ac commit 66fb024

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/deque.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,11 @@ impl<T, const N: usize> Deque<T, N> {
585585
}
586586

587587
fn to_physical_index(&self, index: usize) -> usize {
588-
self.front.wrapping_add(index) % N
588+
let mut res = self.front + index;
589+
if res >= N {
590+
res -= N;
591+
}
592+
res
589593
}
590594
}
591595

0 commit comments

Comments
 (0)