mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-18 13:55:23 -05:00
Remove most old NLL workarounds
Will need full NLL to handle a couple of remaining overlapping mutable borrows.
This commit is contained in:
parent
08069a4e6c
commit
0fd6a6830a
7 changed files with 56 additions and 80 deletions
|
@ -270,9 +270,7 @@ impl FreeTypeRasterizer {
|
|||
fn face_for_glyph(&mut self, glyph_key: GlyphKey, have_recursed: bool) -> Result<FontKey, Error> {
|
||||
let c = glyph_key.c;
|
||||
|
||||
let use_initial_face = if self.faces.contains_key(&glyph_key.font_key) {
|
||||
// Get face and unwrap since we just checked for presence.
|
||||
let face = &self.faces[&glyph_key.font_key];
|
||||
let use_initial_face = if let Some(face) = self.faces.get(&glyph_key.font_key) {
|
||||
let index = face.ft_face.get_char_index(c as usize);
|
||||
|
||||
index != 0 || have_recursed
|
||||
|
|
|
@ -20,6 +20,7 @@ use crate::input::{self, MouseBinding, KeyBinding};
|
|||
use crate::selection::Selection;
|
||||
use crate::sync::FairMutex;
|
||||
use crate::term::{Term, SizeInfo, TermMode, Search};
|
||||
use crate::term::cell::Cell;
|
||||
use crate::util::limit;
|
||||
use crate::util::fmt::Red;
|
||||
use crate::window::Window;
|
||||
|
@ -336,7 +337,7 @@ impl<N: Notify> Processor<N> {
|
|||
if ref_test {
|
||||
// dump grid state
|
||||
let mut grid = processor.ctx.terminal.grid().clone();
|
||||
grid.initialize_all(&::term::cell::Cell::default());
|
||||
grid.initialize_all(&Cell::default());
|
||||
grid.truncate();
|
||||
|
||||
let serialized_grid = json::to_string(&grid)
|
||||
|
|
|
@ -277,8 +277,7 @@ impl<T> Index<usize> for Storage<T> {
|
|||
type Output = Row<T>;
|
||||
#[inline]
|
||||
fn index(&self, index: usize) -> &Self::Output {
|
||||
let index = self.compute_index(index); // borrowck
|
||||
&self.inner[index]
|
||||
&self.inner[self.compute_index(index)]
|
||||
}
|
||||
}
|
||||
|
||||
|
|
18
src/index.rs
18
src/index.rs
|
@ -257,12 +257,8 @@ macro_rules! inclusive {
|
|||
fn next(&mut self) -> Option<$ty> {
|
||||
use crate::index::RangeInclusive::*;
|
||||
|
||||
// this function has a sort of odd structure due to borrowck issues
|
||||
// we may need to replace self.range, so borrows of start and end need to end early
|
||||
|
||||
let at_end;
|
||||
match *self {
|
||||
Empty { .. } => return None, // empty iterators yield no values
|
||||
Empty { .. } => None, // empty iterators yield no values
|
||||
|
||||
NonEmpty { ref mut start, ref mut end } => {
|
||||
|
||||
|
@ -270,15 +266,13 @@ macro_rules! inclusive {
|
|||
if start <= end {
|
||||
let old = *start;
|
||||
*start = old + 1;
|
||||
return Some(old);
|
||||
Some(old)
|
||||
} else {
|
||||
*self = Empty { at: *end };
|
||||
None
|
||||
}
|
||||
at_end = *end;
|
||||
}
|
||||
};
|
||||
|
||||
// got this far; the range is empty, replace it
|
||||
*self = Empty { at: at_end };
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
|
@ -75,9 +75,7 @@ impl<'a> Sampler<'a> {
|
|||
|
||||
impl<'a> Drop for Sampler<'a> {
|
||||
fn drop(&mut self) {
|
||||
// Work around borrowck
|
||||
let duration = self.alive_duration();
|
||||
self.meter.add_sample(duration);
|
||||
self.meter.add_sample(self.alive_duration());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -897,10 +897,8 @@ impl<'a> RenderApi<'a> {
|
|||
};
|
||||
|
||||
// Add cell to batch
|
||||
{
|
||||
let glyph = glyph_cache.get(glyph_key, self);
|
||||
self.add_render_item(&cell, glyph);
|
||||
}
|
||||
let glyph = glyph_cache.get(glyph_key, self); // borrowck multiple mutable borrows
|
||||
self.add_render_item(&cell, glyph);
|
||||
|
||||
// Render zero-width characters
|
||||
for c in (&chars[1..]).iter().filter(|c| **c != ' ') {
|
||||
|
|
|
@ -1366,53 +1366,47 @@ impl ansi::Handler for Term {
|
|||
self.input_needs_wrap = false;
|
||||
}
|
||||
|
||||
{
|
||||
// Number of cells the char will occupy
|
||||
if let Some(width) = c.width() {
|
||||
// Sigh, borrowck making us check the width twice. Hopefully the
|
||||
// optimizer can fix it.
|
||||
let num_cols = self.grid.num_cols();
|
||||
{
|
||||
// If in insert mode, first shift cells to the right.
|
||||
if self.mode.contains(mode::TermMode::INSERT)
|
||||
&& self.cursor.point.col + width < num_cols
|
||||
{
|
||||
let line = self.cursor.point.line; // borrowck
|
||||
let col = self.cursor.point.col;
|
||||
let line = &mut self.grid[line];
|
||||
// Number of cells the char will occupy
|
||||
if let Some(width) = c.width() {
|
||||
let num_cols = self.grid.num_cols();
|
||||
|
||||
let src = line[col..].as_ptr();
|
||||
let dst = line[(col + width)..].as_mut_ptr();
|
||||
unsafe {
|
||||
// memmove
|
||||
ptr::copy(src, dst, (num_cols - col - width).0);
|
||||
}
|
||||
}
|
||||
if width == 0 {
|
||||
let mut col = self.cursor.point.col.0.saturating_sub(1);
|
||||
let line = self.cursor.point.line;
|
||||
if self.grid[line][Column(col)]
|
||||
.flags
|
||||
.contains(cell::Flags::WIDE_CHAR_SPACER)
|
||||
{
|
||||
col.saturating_sub(1);
|
||||
}
|
||||
self.grid[line][Column(col)].push_extra(c);
|
||||
return;
|
||||
}
|
||||
// If in insert mode, first shift cells to the right.
|
||||
if self.mode.contains(mode::TermMode::INSERT)
|
||||
&& self.cursor.point.col + width < num_cols
|
||||
{
|
||||
let line = self.cursor.point.line;
|
||||
let col = self.cursor.point.col;
|
||||
let line = &mut self.grid[line];
|
||||
|
||||
let cell = &mut self.grid[&self.cursor.point];
|
||||
*cell = self.cursor.template;
|
||||
cell.c = self.cursor.charsets[self.active_charset].map(c);
|
||||
|
||||
// Handle wide chars
|
||||
if width == 2 {
|
||||
cell.flags.insert(cell::Flags::WIDE_CHAR);
|
||||
}
|
||||
let src = line[col..].as_ptr();
|
||||
let dst = line[(col + width)..].as_mut_ptr();
|
||||
unsafe {
|
||||
// memmove
|
||||
ptr::copy(src, dst, (num_cols - col - width).0);
|
||||
}
|
||||
}
|
||||
|
||||
// Set spacer cell for wide chars.
|
||||
if width == 2 && self.cursor.point.col + 1 < num_cols {
|
||||
// Handle zero-width characters
|
||||
if width == 0 {
|
||||
let col = self.cursor.point.col.0.saturating_sub(1);
|
||||
let line = self.cursor.point.line;
|
||||
if self.grid[line][Column(col)].flags.contains(cell::Flags::WIDE_CHAR_SPACER)
|
||||
{
|
||||
col.saturating_sub(1);
|
||||
}
|
||||
self.grid[line][Column(col)].push_extra(c);
|
||||
return;
|
||||
}
|
||||
|
||||
let cell = &mut self.grid[&self.cursor.point];
|
||||
*cell = self.cursor.template;
|
||||
cell.c = self.cursor.charsets[self.active_charset].map(c);
|
||||
|
||||
// Handle wide chars
|
||||
if width == 2 {
|
||||
cell.flags.insert(cell::Flags::WIDE_CHAR);
|
||||
|
||||
if self.cursor.point.col + 1 < num_cols {
|
||||
self.cursor.point.col += 1;
|
||||
let spacer = &mut self.grid[&self.cursor.point];
|
||||
*spacer = self.cursor.template;
|
||||
|
@ -1455,15 +1449,13 @@ impl ansi::Handler for Term {
|
|||
#[inline]
|
||||
fn goto_line(&mut self, line: Line) {
|
||||
trace!("goto_line: {}", line);
|
||||
let col = self.cursor.point.col; // borrowck
|
||||
self.goto(line, col)
|
||||
self.goto(line, self.cursor.point.col)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn goto_col(&mut self, col: Column) {
|
||||
trace!("goto_col: {}", col);
|
||||
let line = self.cursor.point.line; // borrowck
|
||||
self.goto(line, col)
|
||||
self.goto(self.cursor.point.line, col)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -1476,8 +1468,7 @@ impl ansi::Handler for Term {
|
|||
let destination = self.cursor.point.col + count;
|
||||
let num_cells = (self.size_info.cols() - destination).0;
|
||||
|
||||
let line = self.cursor.point.line; // borrowck
|
||||
let line = &mut self.grid[line];
|
||||
let line = &mut self.grid[self.cursor.point.line];
|
||||
|
||||
unsafe {
|
||||
let src = line[source..].as_ptr();
|
||||
|
@ -1498,16 +1489,14 @@ impl ansi::Handler for Term {
|
|||
fn move_up(&mut self, lines: Line) {
|
||||
trace!("move_up: {}", lines);
|
||||
let move_to = Line(self.cursor.point.line.0.saturating_sub(lines.0));
|
||||
let col = self.cursor.point.col; // borrowck
|
||||
self.goto(move_to, col)
|
||||
self.goto(move_to, self.cursor.point.col)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn move_down(&mut self, lines: Line) {
|
||||
trace!("move_down: {}", lines);
|
||||
let move_to = self.cursor.point.line + lines;
|
||||
let col = self.cursor.point.col; // borrowck
|
||||
self.goto(move_to, col)
|
||||
self.goto(move_to, self.cursor.point.col)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -1715,8 +1704,7 @@ impl ansi::Handler for Term {
|
|||
let end = min(start + count, self.grid.num_cols() - 1);
|
||||
let n = (self.size_info.cols() - end).0;
|
||||
|
||||
let line = self.cursor.point.line; // borrowck
|
||||
let line = &mut self.grid[line];
|
||||
let line = &mut self.grid[self.cursor.point.line];
|
||||
|
||||
unsafe {
|
||||
let src = line[end..].as_ptr();
|
||||
|
|
Loading…
Reference in a new issue