Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MRF: Use ZSTD streaming API for compression #9230

Merged
merged 1 commit into from
Feb 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions frmts/mrf/mrf_band.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,20 @@ static void *ZstdCompBlock(buf_mgr &src, size_t extrasize, int c_level,
dst = dbuff.data();
}

size_t val =
ZSTD_compressCCtx(cctx, dst, size, src.buffer, src.size, c_level);
// Use the streaming interface, it's faster and better
// See discussion at https://github.com/facebook/zstd/issues/3729
ZSTD_outBuffer output = {dst, size, 0};
ZSTD_inBuffer input = {src.buffer, src.size, 0};
// Set level
ZSTD_CCtx_setParameter(cctx, ZSTD_c_compressionLevel, c_level);
// First, pass a continue flag, otherwise it will compress in one go
size_t val = ZSTD_compressStream2(cctx, &output, &input, ZSTD_e_continue);
// If it worked, pass the end flag to flush the buffer
if (val == 0)
val = ZSTD_compressStream2(cctx, &output, &input, ZSTD_e_end);
if (ZSTD_isError(val))
return nullptr;
val = output.pos;

// If we didn't need the buffer, packed data is already in the user buffer
if (dbuff.empty())
Expand Down
Loading