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 Grid { /// 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];