Skip to content

Commit

Permalink
use ManuallyDrop in Vec::from(bytes_mut)
Browse files Browse the repository at this point in the history
  • Loading branch information
braddunbar committed Mar 2, 2024
1 parent cad19a6 commit 7bf4afd
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/bytes_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1617,6 +1617,7 @@ impl PartialEq<Bytes> for BytesMut {
impl From<BytesMut> for Vec<u8> {
fn from(bytes: BytesMut) -> Self {
let kind = bytes.kind();
let bytes = ManuallyDrop::new(bytes);

let mut vec = if kind == KIND_VEC {
unsafe {
Expand All @@ -1633,7 +1634,7 @@ impl From<BytesMut> for Vec<u8> {

vec
} else {
return bytes.deref().to_vec();
return ManuallyDrop::into_inner(bytes).deref().to_vec();
}
};

Expand All @@ -1644,8 +1645,6 @@ impl From<BytesMut> for Vec<u8> {
vec.set_len(len);
}

mem::forget(bytes);

vec
}
}
Expand Down

0 comments on commit 7bf4afd

Please sign in to comment.