Skip to content

Commit

Permalink
Assume access to nil root branch always exists
Browse files Browse the repository at this point in the history
  • Loading branch information
evenorog committed Oct 9, 2023
1 parent a676add commit 696b4a8
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,15 @@ impl<E: Edit, S: Slot> History<E, S> {
.for_each(|(_, child)| child.parent.index -= 1);
}

// Handle new branch.
// Handle new branch by putting the tail into the empty root branch
// before we swap the root with the new branch.
if !tail.is_empty() {
let next = self.branches.insert(Branch::NIL);
let new = At::new(next, head.index);
if let Some(branch) = self.branches.get_mut(head.root) {
branch.parent = new;
branch.entries = tail;
}
let root = self.branches.get_mut(head.root).unwrap();
debug_assert!(root.entries.is_empty());
root.parent = new;
root.entries = tail;
self.set_root(new, rm_saved);
}

Expand Down Expand Up @@ -396,10 +397,10 @@ impl<E: Edit, S: Slot> History<E, S> {
let (_, _, entries, rm_saved) = self.record.redo_and_push(target, entry);
if !entries.is_empty() {
let new = At::new(id, index);
if let Some(branch) = self.branches.get_mut(self.root) {
branch.parent = new;
branch.entries = entries;
}
let root = self.branches.get_mut(self.root).unwrap();
debug_assert!(root.entries.is_empty());
root.parent = new;
root.entries = entries;
self.set_root(new, rm_saved);
}
}
Expand Down

0 comments on commit 696b4a8

Please sign in to comment.