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> {
|
fn face_for_glyph(&mut self, glyph_key: GlyphKey, have_recursed: bool) -> Result<FontKey, Error> {
|
||||||
let c = glyph_key.c;
|
let c = glyph_key.c;
|
||||||
|
|
||||||
let use_initial_face = if self.faces.contains_key(&glyph_key.font_key) {
|
let use_initial_face = if let Some(face) = self.faces.get(&glyph_key.font_key) {
|
||||||
// Get face and unwrap since we just checked for presence.
|
|
||||||
let face = &self.faces[&glyph_key.font_key];
|
|
||||||
let index = face.ft_face.get_char_index(c as usize);
|
let index = face.ft_face.get_char_index(c as usize);
|
||||||
|
|
||||||
index != 0 || have_recursed
|
index != 0 || have_recursed
|
||||||
|
|
|
@ -20,6 +20,7 @@ use crate::input::{self, MouseBinding, KeyBinding};
|
||||||
use crate::selection::Selection;
|
use crate::selection::Selection;
|
||||||
use crate::sync::FairMutex;
|
use crate::sync::FairMutex;
|
||||||
use crate::term::{Term, SizeInfo, TermMode, Search};
|
use crate::term::{Term, SizeInfo, TermMode, Search};
|
||||||
|
use crate::term::cell::Cell;
|
||||||
use crate::util::limit;
|
use crate::util::limit;
|
||||||
use crate::util::fmt::Red;
|
use crate::util::fmt::Red;
|
||||||
use crate::window::Window;
|
use crate::window::Window;
|
||||||
|
@ -336,7 +337,7 @@ impl<N: Notify> Processor<N> {
|
||||||
if ref_test {
|
if ref_test {
|
||||||
// dump grid state
|
// dump grid state
|
||||||
let mut grid = processor.ctx.terminal.grid().clone();
|
let mut grid = processor.ctx.terminal.grid().clone();
|
||||||
grid.initialize_all(&::term::cell::Cell::default());
|
grid.initialize_all(&Cell::default());
|
||||||
grid.truncate();
|
grid.truncate();
|
||||||
|
|
||||||
let serialized_grid = json::to_string(&grid)
|
let serialized_grid = json::to_string(&grid)
|
||||||
|
|
|
@ -277,8 +277,7 @@ impl<T> Index<usize> for Storage<T> {
|
||||||
type Output = Row<T>;
|
type Output = Row<T>;
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index(&self, index: usize) -> &Self::Output {
|
fn index(&self, index: usize) -> &Self::Output {
|
||||||
let index = self.compute_index(index); // borrowck
|
&self.inner[self.compute_index(index)]
|
||||||
&self.inner[index]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
18
src/index.rs
18
src/index.rs
|
@ -257,12 +257,8 @@ macro_rules! inclusive {
|
||||||
fn next(&mut self) -> Option<$ty> {
|
fn next(&mut self) -> Option<$ty> {
|
||||||
use crate::index::RangeInclusive::*;
|
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 {
|
match *self {
|
||||||
Empty { .. } => return None, // empty iterators yield no values
|
Empty { .. } => None, // empty iterators yield no values
|
||||||
|
|
||||||
NonEmpty { ref mut start, ref mut end } => {
|
NonEmpty { ref mut start, ref mut end } => {
|
||||||
|
|
||||||
|
@ -270,15 +266,13 @@ macro_rules! inclusive {
|
||||||
if start <= end {
|
if start <= end {
|
||||||
let old = *start;
|
let old = *start;
|
||||||
*start = old + 1;
|
*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]
|
#[inline]
|
||||||
|
|
|
@ -75,9 +75,7 @@ impl<'a> Sampler<'a> {
|
||||||
|
|
||||||
impl<'a> Drop for Sampler<'a> {
|
impl<'a> Drop for Sampler<'a> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
// Work around borrowck
|
self.meter.add_sample(self.alive_duration());
|
||||||
let duration = self.alive_duration();
|
|
||||||
self.meter.add_sample(duration);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -897,10 +897,8 @@ impl<'a> RenderApi<'a> {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add cell to batch
|
// Add cell to batch
|
||||||
{
|
let glyph = glyph_cache.get(glyph_key, self); // borrowck multiple mutable borrows
|
||||||
let glyph = glyph_cache.get(glyph_key, self);
|
self.add_render_item(&cell, glyph);
|
||||||
self.add_render_item(&cell, glyph);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render zero-width characters
|
// Render zero-width characters
|
||||||
for c in (&chars[1..]).iter().filter(|c| **c != ' ') {
|
for c in (&chars[1..]).iter().filter(|c| **c != ' ') {
|
||||||
|
|
|
@ -1366,53 +1366,47 @@ impl ansi::Handler for Term {
|
||||||
self.input_needs_wrap = false;
|
self.input_needs_wrap = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
// Number of cells the char will occupy
|
||||||
// Number of cells the char will occupy
|
if let Some(width) = c.width() {
|
||||||
if let Some(width) = c.width() {
|
let num_cols = self.grid.num_cols();
|
||||||
// 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];
|
|
||||||
|
|
||||||
let src = line[col..].as_ptr();
|
// If in insert mode, first shift cells to the right.
|
||||||
let dst = line[(col + width)..].as_mut_ptr();
|
if self.mode.contains(mode::TermMode::INSERT)
|
||||||
unsafe {
|
&& self.cursor.point.col + width < num_cols
|
||||||
// memmove
|
{
|
||||||
ptr::copy(src, dst, (num_cols - col - width).0);
|
let line = self.cursor.point.line;
|
||||||
}
|
let col = self.cursor.point.col;
|
||||||
}
|
let line = &mut self.grid[line];
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
let cell = &mut self.grid[&self.cursor.point];
|
let src = line[col..].as_ptr();
|
||||||
*cell = self.cursor.template;
|
let dst = line[(col + width)..].as_mut_ptr();
|
||||||
cell.c = self.cursor.charsets[self.active_charset].map(c);
|
unsafe {
|
||||||
|
// memmove
|
||||||
// Handle wide chars
|
ptr::copy(src, dst, (num_cols - col - width).0);
|
||||||
if width == 2 {
|
|
||||||
cell.flags.insert(cell::Flags::WIDE_CHAR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Set spacer cell for wide chars.
|
// Handle zero-width characters
|
||||||
if width == 2 && self.cursor.point.col + 1 < num_cols {
|
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;
|
self.cursor.point.col += 1;
|
||||||
let spacer = &mut self.grid[&self.cursor.point];
|
let spacer = &mut self.grid[&self.cursor.point];
|
||||||
*spacer = self.cursor.template;
|
*spacer = self.cursor.template;
|
||||||
|
@ -1455,15 +1449,13 @@ impl ansi::Handler for Term {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn goto_line(&mut self, line: Line) {
|
fn goto_line(&mut self, line: Line) {
|
||||||
trace!("goto_line: {}", line);
|
trace!("goto_line: {}", line);
|
||||||
let col = self.cursor.point.col; // borrowck
|
self.goto(line, self.cursor.point.col)
|
||||||
self.goto(line, col)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn goto_col(&mut self, col: Column) {
|
fn goto_col(&mut self, col: Column) {
|
||||||
trace!("goto_col: {}", col);
|
trace!("goto_col: {}", col);
|
||||||
let line = self.cursor.point.line; // borrowck
|
self.goto(self.cursor.point.line, col)
|
||||||
self.goto(line, col)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -1476,8 +1468,7 @@ impl ansi::Handler for Term {
|
||||||
let destination = self.cursor.point.col + count;
|
let destination = self.cursor.point.col + count;
|
||||||
let num_cells = (self.size_info.cols() - destination).0;
|
let num_cells = (self.size_info.cols() - destination).0;
|
||||||
|
|
||||||
let line = self.cursor.point.line; // borrowck
|
let line = &mut self.grid[self.cursor.point.line];
|
||||||
let line = &mut self.grid[line];
|
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let src = line[source..].as_ptr();
|
let src = line[source..].as_ptr();
|
||||||
|
@ -1498,16 +1489,14 @@ impl ansi::Handler for Term {
|
||||||
fn move_up(&mut self, lines: Line) {
|
fn move_up(&mut self, lines: Line) {
|
||||||
trace!("move_up: {}", lines);
|
trace!("move_up: {}", lines);
|
||||||
let move_to = Line(self.cursor.point.line.0.saturating_sub(lines.0));
|
let move_to = Line(self.cursor.point.line.0.saturating_sub(lines.0));
|
||||||
let col = self.cursor.point.col; // borrowck
|
self.goto(move_to, self.cursor.point.col)
|
||||||
self.goto(move_to, col)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn move_down(&mut self, lines: Line) {
|
fn move_down(&mut self, lines: Line) {
|
||||||
trace!("move_down: {}", lines);
|
trace!("move_down: {}", lines);
|
||||||
let move_to = self.cursor.point.line + lines;
|
let move_to = self.cursor.point.line + lines;
|
||||||
let col = self.cursor.point.col; // borrowck
|
self.goto(move_to, self.cursor.point.col)
|
||||||
self.goto(move_to, col)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -1715,8 +1704,7 @@ impl ansi::Handler for Term {
|
||||||
let end = min(start + count, self.grid.num_cols() - 1);
|
let end = min(start + count, self.grid.num_cols() - 1);
|
||||||
let n = (self.size_info.cols() - end).0;
|
let n = (self.size_info.cols() - end).0;
|
||||||
|
|
||||||
let line = self.cursor.point.line; // borrowck
|
let line = &mut self.grid[self.cursor.point.line];
|
||||||
let line = &mut self.grid[line];
|
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let src = line[end..].as_ptr();
|
let src = line[end..].as_ptr();
|
||||||
|
|
Loading…
Reference in a new issue