aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2016-09-18 18:17:33 -0700
committerJoe Wilm <joe@jwilm.com>2016-09-18 18:17:33 -0700
commit7dd176fea8fa0344c822575fdac255441fe577b3 (patch)
tree41ea69f08a3915567b48f36c1e447ab07104cba4
parentb6f7b39c0dd28755143dd39d90f5d81f7720d760 (diff)
downloadalacritty-7dd176fea8fa0344c822575fdac255441fe577b3.tar.gz
alacritty-7dd176fea8fa0344c822575fdac255441fe577b3.zip
Make use of `unlikely` intrinsic
There's some bounds checks we do that panic if the condition is ever true.
-rw-r--r--src/grid.rs20
-rw-r--r--src/main.rs1
-rw-r--r--src/term.rs6
3 files changed, 16 insertions, 11 deletions
diff --git a/src/grid.rs b/src/grid.rs
index 8dbfd0b5..7acfeaa3 100644
--- a/src/grid.rs
+++ b/src/grid.rs
@@ -145,17 +145,19 @@ impl<T> Grid<T> {
/// better error messages by doing the bounds checking ourselves.
#[inline]
pub fn swap_lines(&mut self, src: index::Line, dst: index::Line) {
- // check that src/dst are in bounds. Since index::Line newtypes usize,
- // we can assume values are positive.
- if src >= self.lines {
- panic!("swap_lines src out of bounds; len={}, src={}", self.raw.len(), src);
- }
-
- if dst >= self.lines {
- panic!("swap_lines dst out of bounds; len={}, dst={}", self.raw.len(), dst);
- }
+ use std::intrinsics::unlikely;
unsafe {
+ // check that src/dst are in bounds. Since index::Line newtypes usize,
+ // we can assume values are positive.
+ if unlikely(src >= self.lines) {
+ panic!("swap_lines src out of bounds; len={}, src={}", self.raw.len(), src);
+ }
+
+ if unlikely(dst >= self.lines) {
+ panic!("swap_lines dst out of bounds; len={}, dst={}", self.raw.len(), dst);
+ }
+
let src: *mut _ = self.raw.get_unchecked_mut(src.0);
let dst: *mut _ = self.raw.get_unchecked_mut(dst.0);
diff --git a/src/main.rs b/src/main.rs
index a803d05c..f1819b64 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -21,6 +21,7 @@
#![feature(step_trait)]
#![feature(custom_derive, plugin)]
#![plugin(serde_macros)]
+#![feature(core_intrinsics)]
extern crate cgmath;
extern crate errno;
diff --git a/src/term.rs b/src/term.rs
index 44d0d7d6..58f60b87 100644
--- a/src/term.rs
+++ b/src/term.rs
@@ -467,8 +467,10 @@ impl ansi::Handler for Term {
self.cursor.col = Column(0);
}
- if self.cursor.line == self.grid.num_lines() {
- panic!("cursor fell off grid");
+ unsafe {
+ if ::std::intrinsics::unlikely(self.cursor.line == self.grid.num_lines()) {
+ panic!("cursor fell off grid");
+ }
}
let cell = &mut self.grid[&self.cursor];