diff options
author | Blaž Hrastnik | 2021-02-16 04:37:58 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-02-16 04:39:04 +0000 |
commit | 9821c4dd3b41d4e1ad07208e3c65b5cb96b7ecec (patch) | |
tree | b826619e92bdc6eb0bc4ee1a4dc8241c1c2b09ae /helix-view/src | |
parent | b0b5451c389b0d893cef4b30df8982a32d22bc9e (diff) |
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
}
}
}
Diffstat (limited to 'helix-view/src')
0 files changed, 0 insertions, 0 deletions