mirror of
https://github.com/alacritty/alacritty.git
synced 2026-12-01 01:14:32 +03:00
Make use of unlikely intrinsic
There's some bounds checks we do that panic if the condition is ever true.
This commit is contained in:
1 parent
b6f7b39c0d
commit
7dd176fea8
3 files changed
+16
-11
No files matched your search
+11
-9
@@ -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);
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#![feature(step_trait)]
|
||||
#![feature(custom_derive, plugin)]
|
||||
#![plugin(serde_macros)]
|
||||
#![feature(core_intrinsics)]
|
||||
|
||||
extern crate cgmath;
|
||||
extern crate errno;
|
||||
|
||||
+4
-2
@@ -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];
|
||||
|
||||
Reference in new issue
Block a user