From f2cae6a1948b6e104ff4b53993f44a7d3cc0b287 Mon Sep 17 00:00:00 2001 From: "Evgeniy A. Dushistov" Date: Sat, 14 Dec 2024 21:57:10 +0300 Subject: [PATCH] use more optimized method for Vec to Bytes conversation Bytes::from_owner is "generic" method, for any "owners" of [u8], while specialized "impl From> for Bytes" can be faster in some cases, for example if capacity==len, then it is almost no-op. --- src/protocol/frame/payload.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/protocol/frame/payload.rs b/src/protocol/frame/payload.rs index 8f3c073f..bac37182 100644 --- a/src/protocol/frame/payload.rs +++ b/src/protocol/frame/payload.rs @@ -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(_) => {} }