From: Nick Magerko Date: Mon, 19 Aug 2019 16:01:31 +0000 (-0700) Subject: Set pledged size just before compression X-Git-Tag: v1.4.4~1^2~74^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c403b12f9dbab9ba3ab30fca6e1ce3c31d2f8923;p=thirdparty%2Fzstd.git Set pledged size just before compression --- diff --git a/programs/fileio.c b/programs/fileio.c index 82d70075b..75b271a8f 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -704,21 +704,7 @@ static cRess_t FIO_createCResources(FIO_prefs_t* const prefs, CHECK( ZSTD_CCtx_setParameter(ress.cctx, ZSTD_c_rsyncable, prefs->rsyncable) ); #endif /* dictionary */ - /* set the pledged size for dictionary loading, to adapt compression parameters */ - if (srcSize == ZSTD_CONTENTSIZE_UNKNOWN && prefs->streamSrcSize > 0) { - /* unknown source size; use the declared stream size and disable writing this size to frame during compression */ - CHECK( ZSTD_CCtx_setPledgedSrcSize(ress.cctx, prefs->streamSrcSize) ); - CHECK( ZSTD_CCtx_setParameter(ress.cctx, ZSTD_c_contentSizeFlag, 0) ); - } else { - /* use the known source size for adaption */ - CHECK( ZSTD_CCtx_setPledgedSrcSize(ress.cctx, srcSize) ); - } CHECK( ZSTD_CCtx_loadDictionary(ress.cctx, dictBuffer, dictBuffSize) ); - if (srcSize != ZSTD_CONTENTSIZE_UNKNOWN || prefs->streamSrcSize == 0) { - /* reset pledge when src size is known or stream size is declared */ - CHECK( ZSTD_CCtx_setPledgedSrcSize(ress.cctx, ZSTD_CONTENTSIZE_UNKNOWN) ); - } - free(dictBuffer); } @@ -1020,6 +1006,10 @@ FIO_compressZstdFrame(FIO_prefs_t* const prefs, /* init */ if (fileSize != UTIL_FILESIZE_UNKNOWN) { CHECK(ZSTD_CCtx_setPledgedSrcSize(ress.cctx, fileSize)); + } else if (prefs->streamSrcSize > 0) { + /* unknown source size; use the declared stream size and disable writing this size to frame during compression */ + CHECK( ZSTD_CCtx_setPledgedSrcSize(ress.cctx, prefs->streamSrcSize) ); + CHECK( ZSTD_CCtx_setParameter(ress.cctx, ZSTD_c_contentSizeFlag, 0) ); } (void)srcFileName;