From 569e2abccd397c26539188cf5ac788bb592f1246 Mon Sep 17 00:00:00 2001 From: Nick Terrell Date: Mon, 9 Apr 2018 12:09:28 -0700 Subject: [PATCH] Allow negative compression levels in training * Set `dictCLevel` in `zstdcli.c`. * Only set to default level if the compression level `== 0`, not `<= 0`. --- lib/dictBuilder/zdict.c | 6 +++--- programs/zstdcli.c | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/dictBuilder/zdict.c b/lib/dictBuilder/zdict.c index 7d24e4991..427438f01 100644 --- a/lib/dictBuilder/zdict.c +++ b/lib/dictBuilder/zdict.c @@ -724,7 +724,7 @@ static size_t ZDICT_analyzeEntropy(void* dstBuffer, size_t maxDstSize, memset(repOffset, 0, sizeof(repOffset)); repOffset[1] = repOffset[4] = repOffset[8] = 1; memset(bestRepOffset, 0, sizeof(bestRepOffset)); - if (compressionLevel<=0) compressionLevel = g_compressionLevel_default; + if (compressionLevel==0) compressionLevel = g_compressionLevel_default; params = ZSTD_getParams(compressionLevel, averageSampleSize, dictBufferSize); { size_t const beginResult = ZSTD_compressBegin_advanced(esr.ref, dictBuffer, dictBufferSize, params, 0); if (ZSTD_isError(beginResult)) { @@ -873,7 +873,7 @@ size_t ZDICT_finalizeDictionary(void* dictBuffer, size_t dictBufferCapacity, size_t hSize; #define HBUFFSIZE 256 /* should prove large enough for all entropy headers */ BYTE header[HBUFFSIZE]; - int const compressionLevel = (params.compressionLevel <= 0) ? g_compressionLevel_default : params.compressionLevel; + int const compressionLevel = (params.compressionLevel == 0) ? g_compressionLevel_default : params.compressionLevel; U32 const notificationLevel = params.notificationLevel; /* check conditions */ @@ -918,7 +918,7 @@ size_t ZDICT_addEntropyTablesFromBuffer_advanced(void* dictBuffer, size_t dictCo const void* samplesBuffer, const size_t* samplesSizes, unsigned nbSamples, ZDICT_params_t params) { - int const compressionLevel = (params.compressionLevel <= 0) ? g_compressionLevel_default : params.compressionLevel; + int const compressionLevel = (params.compressionLevel == 0) ? g_compressionLevel_default : params.compressionLevel; U32 const notificationLevel = params.notificationLevel; size_t hSize = 8; diff --git a/programs/zstdcli.c b/programs/zstdcli.c index c35de7ccf..24488191f 100644 --- a/programs/zstdcli.c +++ b/programs/zstdcli.c @@ -550,7 +550,9 @@ int main(int argCount, const char* argv[]) U32 fastLevel; ++argument; fastLevel = readU32FromChar(&argument); - if (fastLevel) cLevel = - (int)fastLevel; + if (fastLevel) { + dictCLevel = cLevel = -(int)fastLevel; + } } else if (*argument != 0) { /* Invalid character following --fast */ CLEAN_RETURN(badusage(programName));