Skip to content

Commit

Permalink
use more optimized method for Vec<u8> to Bytes conversation
Browse files Browse the repository at this point in the history
Bytes::from_owner is "generic" method, for any "owners" of [u8],
while specialized "impl From<Vec<u8>> for Bytes" can be faster
in some cases, for example if capacity==len, then it is almost no-op.
  • Loading branch information
Dushistov authored and daniel-abramov committed Dec 15, 2024
1 parent 3e8382c commit f2cae6a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/protocol/frame/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl Payload {
*self = Self::Shared(mem::take(data).freeze());
}
Self::Vec(data) => {
*self = Self::Shared(Bytes::from_owner(mem::take(data)));
*self = Self::Shared(Bytes::from(mem::take(data)));
}
Self::Shared(_) => {}
}
Expand Down

0 comments on commit f2cae6a

Please sign in to comment.