From e74b16b3a2d3404e60d3c89788f35a4667f12156 Mon Sep 17 00:00:00 2001 From: trinity-1686a Date: Sat, 25 Feb 2023 15:02:51 +0100 Subject: [PATCH] make vecdeque contiguous before shrinking it --- src/mem/queue.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/mem/queue.rs b/src/mem/queue.rs index a954726..410efb2 100644 --- a/src/mem/queue.rs +++ b/src/mem/queue.rs @@ -27,9 +27,13 @@ impl RollingBuffer { } fn drain_start(&mut self, pos: usize) { - let before_len = self.len(); + let target_len = 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_len { + self.buffer.make_contiguous(); + self.buffer.shrink_to(target_len); + } } fn extend(&mut self, slice: &[u8]) {