diff options
author | Joe Wilm <joe@jwilm.com> | 2016-09-18 18:17:33 -0700 |
---|---|---|
committer | Joe Wilm <joe@jwilm.com> | 2016-09-18 18:17:33 -0700 |
commit | 7dd176fea8fa0344c822575fdac255441fe577b3 (patch) | |
tree | 41ea69f08a3915567b48f36c1e447ab07104cba4 /src/grid.rs | |
parent | b6f7b39c0dd28755143dd39d90f5d81f7720d760 (diff) | |
download | alacritty-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.
Diffstat (limited to 'src/grid.rs')
-rw-r--r-- | src/grid.rs | 20 |
1 files changed, 11 insertions, 9 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); |