You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
helix-plus/helix-core
Blaž Hrastnik 9821c4dd3b Optimize Changeset::is_empty()
Checked the ASM output for these three options:

pub enum Operation {
    /// Move cursor by n characters.
    Retain(usize),
    /// Delete n characters.
    Delete(usize),
    /// Insert text at position.
    Insert(String),
}

pub struct A {
    changes: Vec<Operation>,
    len: usize,
}

impl A {
    pub fn is_empty1(&self) -> bool {
        match self.changes.as_slice() {
            [] => true,
            [Operation::Retain(_)] => true,
            _ => false,
        }
    }

    /// `true` when the set is empty.
    pub fn is_empty2(&self) -> bool {
        let len = self.changes.len();
        len == 0
        || (
            len == 1
            && self.changes[0] == Operation::Retain(self.len)
        )

    }

    pub fn is_empty3(&self) -> bool {
        match self.changes.as_slice() {
            [] | [Operation::Retain(_)] => true,
            _ => false
        }
    }

}
3 years ago
..
src Optimize Changeset::is_empty() 3 years ago
.gitignore Initial import. 4 years ago
Cargo.toml Extend selection commands. 4 years ago