Skip to content

Commit 016fdbd

Browse files
authored
Reserve capacity in BytesMut::put (#794)
1 parent ef7f257 commit 016fdbd

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/bytes_mut.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,9 @@ unsafe impl BufMut for BytesMut {
12101210
Err(bytes) => self.extend_from_slice(&bytes),
12111211
}
12121212
} else {
1213+
// In case the src isn't contiguous, reserve upfront.
1214+
self.reserve(src.remaining());
1215+
12131216
while src.has_remaining() {
12141217
let s = src.chunk();
12151218
let l = s.len();

0 commit comments

Comments
 (0)