1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2024-11-18 13:55:23 -05:00

Remove checking on remainder op

The length of the underlying storage will *never* be zero.

This removes generated code that branches on the possibility that len is
zero.
This commit is contained in:
Joe Wilm 2018-05-19 15:58:49 -07:00
parent fc2ef0991e
commit 37b8fd8cf5

View file

@ -174,6 +174,14 @@ impl<T> Storage<T> {
/// Compute actual index in underlying storage given the requested index.
fn compute_index(&self, requested: usize) -> usize {
use ::std::hint::unreachable_unchecked;
// This prevents an extra branch being inserted which checks for the
// divisor to be zero thus making a % b generate equivalent code as in C
if self.inner.len() == 0 {
unsafe { unreachable_unchecked(); }
}
(requested + self.zero) % self.inner.len()
}