Commit 0ccda02d authored by Michael Aaron Murphy's avatar Michael Aaron Murphy

Merge branch 'optimize' into 'master'

Optimize via Clippy & Thread-Local Buffer

See merge request !9
parents 29e4434e 2aa8516e
......@@ -158,7 +158,7 @@ impl Buffer {
}
pub fn revert(&mut self) -> bool {
if self.actions.len() == 0 {
if self.actions.is_empty() {
return false;
}
......@@ -228,7 +228,7 @@ impl Buffer {
}
pub fn range_chars(&self, start: usize, end: usize) -> Vec<char> {
self.data[start..end].iter().cloned().collect()
self.data[start..end].to_owned()
}
pub fn width(&self) -> Vec<usize> {
......@@ -292,13 +292,12 @@ impl Buffer {
pub fn starts_with(&self, other: &Buffer) -> bool {
let other_len = other.data.len();
let self_len = self.data.len();
if other.data.len() != 0 && self_len != other_len {
if ! other.data.is_empty() && self_len != other_len {
let match_let = self.data
.iter()
.zip(&other.data)
.take_while(|&(s, o)| *s == *o)
.collect::<Vec<_>>()
.len();
.count();
match_let == other_len
} else {
false
......
......@@ -40,7 +40,7 @@ impl Completer for FilenameCompleter {
let start_owned: String = if start.starts_with('\"') || start.starts_with('\'') {
start = &start[1..];
if start.len() >= 1 {
if ! start.is_empty() {
start = &start[..start.len() - 1];
}
start.into()
......@@ -64,7 +64,7 @@ impl Completer for FilenameCompleter {
let completing_dir;
match full_path.parent() {
// XXX non-unix separaor
Some(parent) if !start.is_empty() && !start_owned.ends_with("/") &&
Some(parent) if !start.is_empty() && !start_owned.ends_with('/') &&
!full_path.ends_with("..") => {
p = parent;
start_name = full_path
......@@ -76,7 +76,7 @@ impl Completer for FilenameCompleter {
_ => {
p = full_path.as_path();
start_name = "".into();
completing_dir = start.is_empty() || start.ends_with("/") || full_path.ends_with("..");
completing_dir = start.is_empty() || start.ends_with('/') || full_path.ends_with("..");
}
}
......
......@@ -25,10 +25,8 @@ pub fn get_buffer_words(buf: &Buffer) -> Vec<(usize, usize)> {
res.push((start, i));
word_start = None;
}
} else {
if c != ' ' {
word_start = Some(i);
}
} else if c != ' ' {
word_start = Some(i);
}
just_had_backslash = false;
......
This diff is collapsed.
......@@ -4,7 +4,7 @@ use std::{
collections::{vec_deque, VecDeque},
io::{BufRead, BufReader, BufWriter},
fs::File,
io::{self, Seek, SeekFrom, Write},
io::{self, Write},
iter::IntoIterator,
ops::Index,
ops::IndexMut,
......@@ -115,7 +115,7 @@ impl History {
curr_position: Option<usize>,
new_buff: &'b Buffer,
) -> Option<&'a Buffer> {
let pos = curr_position.unwrap_or(self.buffers.len());
let pos = curr_position.unwrap_or_else(|| self.buffers.len());
for iter in (0..pos).rev() {
if let Some(tested) = self.buffers.get(iter) {
if tested.starts_with(new_buff) {
......
......@@ -45,7 +45,7 @@ impl ModeStack {
/// If the stack is empty, we are in normal mode.
fn mode(&self) -> Mode {
self.0.last()
.map(|&m| m)
.cloned()
.unwrap_or(Mode::Normal)
}
......@@ -92,18 +92,18 @@ enum ViMoveDir {
}
impl ViMoveDir {
pub fn advance(&self, cursor: &mut usize, max: usize) -> bool {
self.move_cursor(cursor, max, *self)
pub fn advance(self, cursor: &mut usize, max: usize) -> bool {
self.move_cursor(cursor, max, self)
}
pub fn go_back(&self, cursor: &mut usize, max: usize) -> bool {
match *self {
pub fn go_back(self, cursor: &mut usize, max: usize) -> bool {
match self {
ViMoveDir::Right => self.move_cursor(cursor, max, ViMoveDir::Left),
ViMoveDir::Left => self.move_cursor(cursor, max, ViMoveDir::Right),
}
}
fn move_cursor(&self, cursor: &mut usize, max: usize, dir: ViMoveDir) -> bool {
fn move_cursor(self, cursor: &mut usize, max: usize, dir: ViMoveDir) -> bool {
if dir == ViMoveDir::Right && *cursor == max {
return false;
}
......@@ -272,8 +272,7 @@ fn find_char(buf: &::buffer::Buffer, start: usize, ch: char, count: usize) -> Op
.enumerate()
.skip(start)
.filter(|&(_, &c)| c == ch)
.skip(count - 1)
.next()
.nth(count - 1)
.map(|(i, _)| i)
}
......@@ -285,8 +284,7 @@ fn find_char_rev(buf: &::buffer::Buffer, start: usize, ch: char, count: usize) -
.rev()
.skip(rstart)
.filter(|&(_, &c)| c == ch)
.skip(count - 1)
.next()
.nth(count - 1)
.map(|(i, _)| i)
}
......
......@@ -10,14 +10,14 @@ pub fn last_prompt_line_width<S: AsRef<str>>(s: S) -> usize {
}
pub fn find_longest_common_prefix<T: Clone + Eq>(among: &[Vec<T>]) -> Option<Vec<T>> {
if among.len() == 0 {
if among.is_empty() {
return None;
} else if among.len() == 1 {
return Some(among[0].clone());
}
for s in among {
if s.len() == 0 {
if s.is_empty() {
return None;
}
}
......@@ -100,7 +100,7 @@ pub fn terminal_width() -> io::Result<usize> {
if cfg!(test) {
Ok(80 as usize)
} else {
let (mut size_col, _) = termion::terminal_size()?;
let (mut size_col, _) = ::termion::terminal_size()?;
if size_col == 0 {
size_col = 80;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment