mononoke: use Bytes for ContentChunk thrift

Summary: Can reduce number of allocations and copies by sharing the underlying thrift buffer

Reviewed By: markbt

Differential Revision: D27043232

fbshipit-source-id: a6e58c53035cb07f7b205df465a9ba2f7a78d52e
This commit is contained in:
Alex Hornby 2021-03-26 04:09:10 -07:00 committed by Facebook GitHub Bot
parent fc7e4d9e33
commit c5a1fa65a3
2 changed files with 4 additions and 4 deletions

View File

@ -143,7 +143,7 @@ union FileContents {
}
union ContentChunk {
1: binary Bytes,
1: binary_bytes Bytes,
}
// Payload of object which is an alias

View File

@ -41,11 +41,11 @@ impl ContentChunk {
}
pub(crate) fn into_thrift(self) -> thrift::ContentChunk {
thrift::ContentChunk::Bytes(self.0.to_vec())
thrift::ContentChunk::Bytes(self.0)
}
pub fn from_encoded_bytes(encoded_bytes: Bytes) -> Result<Self> {
let thrift_tc = compact_protocol::deserialize(encoded_bytes.as_ref())
let thrift_tc = compact_protocol::deserialize(encoded_bytes)
.with_context(|| ErrorKind::BlobDeserializeError("ContentChunk".into()))?;
Self::from_thrift(thrift_tc)
}
@ -76,7 +76,7 @@ impl BlobstoreValue for ContentChunk {
}
fn from_blob(blob: ContentChunkBlob) -> Result<Self> {
let thrift_tc = compact_protocol::deserialize(blob.data().as_ref())
let thrift_tc = compact_protocol::deserialize(blob.data())
.with_context(|| ErrorKind::BlobDeserializeError("ContentChunk".into()))?;
Self::from_thrift(thrift_tc)
}