aboutsummaryrefslogtreecommitdiff
path: root/src/bytes_mut.rs
diff options
context:
space:
mode:
authorGravatar Bryan Donlan <bdonlan@amazon.com> 2020-07-08 20:38:54 +0000
committerGravatar Sean McArthur <sean@seanmonstar.com> 2020-07-08 15:28:36 -0700
commit81550da474bcd243b9e8765c6555831310a954e8 (patch)
tree57f8c193605bd304479958da5297f545c783cc78 /src/bytes_mut.rs
parent90e7e650c99b6d231017d9b831a01e95b8c06756 (diff)
downloadbytes-81550da474bcd243b9e8765c6555831310a954e8.tar.gz
bytes-81550da474bcd243b9e8765c6555831310a954e8.tar.zst
bytes-81550da474bcd243b9e8765c6555831310a954e8.zip
BytesMut: Reuse buffer when data fully consumed via Buf
Closes #412
Diffstat (limited to 'src/bytes_mut.rs')
-rw-r--r--src/bytes_mut.rs5
1 files changed, 2 insertions, 3 deletions
diff --git a/src/bytes_mut.rs b/src/bytes_mut.rs
index 4bfe0ff..e3fa48f 100644
--- a/src/bytes_mut.rs
+++ b/src/bytes_mut.rs
@@ -559,9 +559,8 @@ impl BytesMut {
unsafe {
let (off, prev) = self.get_vec_pos();
- // Only reuse space if we stand to gain at least capacity/2
- // bytes of space back
- if off >= additional && off >= (self.cap / 2) {
+ // Only reuse space if we can satisfy the requested additional space.
+ if self.capacity() - self.len() + off >= additional {
// There's space - reuse it
//
// Just move the pointer back to the start after copying