]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Set pledged size just before compression
authorNick Magerko <nmagerko@fb.com>
Mon, 19 Aug 2019 16:01:31 +0000 (09:01 -0700)
committerNick Magerko <nmagerko@fb.com>
Mon, 19 Aug 2019 16:01:31 +0000 (09:01 -0700)
programs/fileio.c

index 82d70075b60839d3e4de26ba25d475857a8d439f..75b271a8feef545f9ebf49aadee08881bb910c6e 100644 (file)
@@ -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;