From: Nick Terrell Date: Mon, 12 Oct 2020 20:51:35 +0000 (-0700) Subject: [lib] Set ZSTD_c_stable{In,Out}Buffer in ZSTD_compress2() X-Git-Tag: v1.4.7~38^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=809b2f2071c032a71cb91441db94e3f3825d2087;p=thirdparty%2Fzstd.git [lib] Set ZSTD_c_stable{In,Out}Buffer in ZSTD_compress2() Sets these parameters in ZSTD_compress2() then resets them to their orignal values after the compression call. An alternative design could be to add a flush mode `ZSTD_e_singlePass` which implies `ZSTD_c_stable{In,Out}Buffer` but only for a single compression call, by directly setting the applied parameters. I've opted for the smaller change, but this is open for discussion. --- diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index 3041c53ee..a7ab4dea3 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -4364,14 +4364,22 @@ size_t ZSTD_compress2(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize) { + ZSTD_bufferMode_e const originalInBufferMode = cctx->requestedParams.inBufferMode; + ZSTD_bufferMode_e const originalOutBufferMode = cctx->requestedParams.outBufferMode; DEBUGLOG(4, "ZSTD_compress2 (srcSize=%u)", (unsigned)srcSize); ZSTD_CCtx_reset(cctx, ZSTD_reset_session_only); + /* Enable stable input/output buffers. */ + cctx->requestedParams.inBufferMode = ZSTD_bm_stable; + cctx->requestedParams.outBufferMode = ZSTD_bm_stable; { size_t oPos = 0; size_t iPos = 0; size_t const result = ZSTD_compressStream2_simpleArgs(cctx, dst, dstCapacity, &oPos, src, srcSize, &iPos, ZSTD_e_end); + /* Reset to the original values. */ + cctx->requestedParams.inBufferMode = originalInBufferMode; + cctx->requestedParams.outBufferMode = originalOutBufferMode; FORWARD_IF_ERROR(result, "ZSTD_compressStream2_simpleArgs failed"); if (result != 0) { /* compression not completed, due to lack of output space */ assert(oPos == dstCapacity);