Skip to content

Commit

Permalink
ensuring that cap is set correctly following gap buffer realloc
Browse files Browse the repository at this point in the history
  • Loading branch information
sminez committed Mar 5, 2025
1 parent 348f313 commit 649c498
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/buffer/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,12 +635,12 @@ impl GapBuffer {
self.next_gap = clamp_gap_size(self.len() + n, n.next_power_of_two());
}

let gap_increase = self.next_gap + n - self.gap();
let gap_increase = self.next_gap + n;
let cap = self.cap + self.next_gap + n;
let mut buf = Vec::with_capacity(cap);

buf.extend_from_slice(&self.data[..self.gap_start]); // data to gap
buf.resize(buf.len() + self.next_gap + n, 0); // the new gap (zeroed)
buf.resize(buf.len() + self.next_gap + self.gap() + n, 0); // the new gap (zeroed)
buf.extend_from_slice(&self.data[self.gap_end..]); // data after gap

let start = self.gap_start;
Expand Down

0 comments on commit 649c498

Please sign in to comment.