mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-13 00:00:32 +02:00
fix: BytesMut only reuse if src has remaining (#803)
Signed-off-by: discord9 <[email protected]>
This commit is contained in:
+5
-2
@@ -1202,8 +1202,11 @@ unsafe impl BufMut for BytesMut {
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
// When capacity is zero, try reusing allocation of `src`.
|
||||
if self.capacity() == 0 {
|
||||
if !src.has_remaining() {
|
||||
// prevent calling `copy_to_bytes`->`put`->`copy_to_bytes` infintely when src is empty
|
||||
return;
|
||||
} else if self.capacity() == 0 {
|
||||
// When capacity is zero, try reusing allocation of `src`.
|
||||
let src_copy = src.copy_to_bytes(src.remaining());
|
||||
drop(src);
|
||||
match src_copy.try_into_mut() {
|
||||
|
||||
Reference in New Issue
Block a user