Skip to content

Commit

Permalink
chore(memory): avoid useless alloc in Cursor::hit (#212)
Browse files Browse the repository at this point in the history
- Used lazy evaluation where needed
  • Loading branch information
pythonbrad authored Mar 27, 2024
1 parent 4a814b1 commit c0021e2
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions memory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,15 +382,14 @@ impl Cursor {
.buffer
.iter()
.last()
.unwrap_or(&Rc::new(Node::default()))
.goto(character)
.and_then(|node| node.goto(character))
.or_else(|| {
// We end the current sequence
self.insert(Rc::new(Node::default()));
// and start a new one
self.root.goto(character)
})
.unwrap_or(Rc::new(Node::new(character, 0)));
.unwrap_or_else(|| Rc::new(Node::new(character, 0)));

let out = node.take();
self.insert(node);
Expand Down

0 comments on commit c0021e2

Please sign in to comment.