Skip to content

Commit

Permalink
make vecdeque contiguous before shrinking it (#30)
Browse files Browse the repository at this point in the history
work around a standard library bug
  • Loading branch information
trinity-1686a authored Feb 27, 2023
1 parent a7d22c8 commit 1c864ed
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/mem/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ impl RollingBuffer {
}

fn drain_start(&mut self, pos: usize) {
let before_len = self.len();
let target_capacity = self.len() * 9 / 8;
self.buffer.drain(..pos);
self.buffer.shrink_to(before_len * 9 / 8);
// TODO this is a workarround for https://github.com/rust-lang/rust/issues/108453
if self.buffer.capacity() > target_capacity {
self.buffer.make_contiguous();
self.buffer.shrink_to(target_capacity);
}
}

fn extend(&mut self, slice: &[u8]) {
Expand Down

0 comments on commit 1c864ed

Please sign in to comment.