Skip to content

Commit

Permalink
use ManuallyDrop in BytesMut#from_vec
Browse files Browse the repository at this point in the history
  • Loading branch information
braddunbar committed Mar 2, 2024
1 parent 92bf9d4 commit cad19a6
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/bytes_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -828,11 +828,11 @@ impl BytesMut {
// internal change could make a simple pattern (`BytesMut::from(vec)`)
// suddenly a lot more expensive.
#[inline]
pub(crate) fn from_vec(mut vec: Vec<u8>) -> BytesMut {
pub(crate) fn from_vec(vec: Vec<u8>) -> BytesMut {
let mut vec = ManuallyDrop::new(vec);
let ptr = vptr(vec.as_mut_ptr());
let len = vec.len();
let cap = vec.capacity();
mem::forget(vec);

let original_capacity_repr = original_capacity_to_repr(cap);
let data = (original_capacity_repr << ORIGINAL_CAPACITY_OFFSET) | KIND_VEC;
Expand Down

0 comments on commit cad19a6

Please sign in to comment.