From 182524b8842c81b91c20f30d97880081ec0b9a9a Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Sat, 19 May 2018 15:58:49 -0700 Subject: [PATCH] Remove checking on remainder op The length of the underlying storage will *never* be zero. --- src/grid/storage.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/grid/storage.rs b/src/grid/storage.rs index eb87c622..ea220159 100644 --- a/src/grid/storage.rs +++ b/src/grid/storage.rs @@ -178,6 +178,14 @@ impl Storage { /// 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() }