feat: share decompressor buffer (#5777)

This commit is contained in:
joshieDo
2023-12-18 10:42:48 +00:00
committed by GitHub
parent 43f29fe7c2
commit 1d25829f2e
3 changed files with 43 additions and 35 deletions

View File

@ -115,20 +115,11 @@ fn generate_from_compact(fields: &FieldList, ident: &Ident, is_zstd: bool) -> To
quote! {
if flags.__zstd() != 0 {
#decompressor.with(|decompressor| {
let mut decompressor = decompressor.borrow_mut();
let mut tmp: Vec<u8> = Vec::with_capacity(300);
while let Err(err) = decompressor.decompress_to_buffer(&buf[..], &mut tmp) {
let err = err.to_string();
if !err.contains("Destination buffer is too small") {
panic!("Failed to decompress: {}", err);
}
tmp.reserve(tmp.capacity() + 10_000);
}
let decompressor = &mut decompressor.borrow_mut();
let decompressed = decompressor.decompress(buf);
let mut original_buf = buf;
let mut buf: &[u8] = tmp.as_slice();
let mut buf: &[u8] = decompressed;
#(#lines)*
(obj, original_buf)
})