summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/grid/storage.rs8
1 files changed, 8 insertions, 0 deletions
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<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()
}