aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2018-05-19 15:58:49 -0700
committerJoe Wilm <joe@jwilm.com>2018-05-29 21:46:53 -0700
commit37b8fd8cf56292765b6749bc7b088fa7fd1565c8 (patch)
tree6d32e2784e24470a30866e3af3307e83ed088b5a
parentfc2ef0991ef2205fd975a95298bc98823015b791 (diff)
downloadalacritty-scroll/impossible-zero.tar.gz
alacritty-scroll/impossible-zero.zip
Remove checking on remainder opscroll/impossible-zero
The length of the underlying storage will *never* be zero. This removes generated code that branches on the possibility that len is zero.
-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()
}