From 37b8fd8cf56292765b6749bc7b088fa7fd1565c8 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. This removes generated code that branches on the possibility that len is zero. --- src/grid/storage.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/grid/storage.rs b/src/grid/storage.rs index d517fa01..9a56872e 100644 --- a/src/grid/storage.rs +++ b/src/grid/storage.rs @@ -174,6 +174,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() }