Minor fix

This commit is contained in:
Jennifer Liu
2018-07-20 17:41:22 -07:00
parent 71e767ac09
commit b6c5d4982c
@@ -78,7 +78,7 @@ dictInfo* createDictFromFiles(sampleInfo *info, unsigned maxDictSize,
DEFAULT_DISPLAYLEVEL; /* no dict */ DEFAULT_DISPLAYLEVEL; /* no dict */
void* const dictBuffer = malloc(maxDictSize); void* const dictBuffer = malloc(maxDictSize);
dictInfo* dInfo; dictInfo* dInfo = NULL;
/* Checks */ /* Checks */
if (!dictBuffer) if (!dictBuffer)
@@ -118,16 +118,16 @@ double compressWithDict(sampleInfo *srcInfo, dictInfo* dInfo, int compressionLev
/* Local variables */ /* Local variables */
size_t totalCompressedSize = 0; size_t totalCompressedSize = 0;
size_t totalOriginalSize = 0; size_t totalOriginalSize = 0;
unsigned hasDict = dInfo->dictSize > 0 ? 1 : 0; const unsigned hasDict = dInfo->dictSize > 0 ? 1 : 0;
double cRatio; double cRatio;
size_t dstCapacity; size_t dstCapacity;
int i; int i;
/* Pointers */ /* Pointers */
ZSTD_CCtx* cctx; ZSTD_CDict *cdict = NULL;
ZSTD_CDict *cdict; ZSTD_CCtx* cctx = NULL;
size_t *offsets; size_t *offsets = NULL;
void* dst; void* dst = NULL;
/* Allocate dst with enough space to compress the maximum sized sample */ /* Allocate dst with enough space to compress the maximum sized sample */
{ {
@@ -150,7 +150,7 @@ double compressWithDict(sampleInfo *srcInfo, dictInfo* dInfo, int compressionLev
cctx = ZSTD_createCCtx(); cctx = ZSTD_createCCtx();
if(!cctx || !dst) { if(!cctx || !dst) {
cRatio = -1; cRatio = -1;
goto _nodictCleanup; goto _cleanup;
} }
/* Create CDict if there's a dictionary stored on buffer */ /* Create CDict if there's a dictionary stored on buffer */
@@ -158,7 +158,7 @@ double compressWithDict(sampleInfo *srcInfo, dictInfo* dInfo, int compressionLev
cdict = ZSTD_createCDict(dInfo->dictBuffer, dInfo->dictSize, compressionLevel); cdict = ZSTD_createCDict(dInfo->dictBuffer, dInfo->dictSize, compressionLevel);
if(!cdict) { if(!cdict) {
cRatio = -1; cRatio = -1;
goto _dictCleanup; goto _cleanup;
} }
} }
@@ -173,8 +173,7 @@ double compressWithDict(sampleInfo *srcInfo, dictInfo* dInfo, int compressionLev
} }
if (ZSTD_isError(compressedSize)) { if (ZSTD_isError(compressedSize)) {
cRatio = -1; cRatio = -1;
if(hasDict) goto _dictCleanup; goto _cleanup;
else goto _nodictCleanup;
} }
totalCompressedSize += compressedSize; totalCompressedSize += compressedSize;
} }
@@ -189,14 +188,11 @@ double compressWithDict(sampleInfo *srcInfo, dictInfo* dInfo, int compressionLev
DISPLAYLEVEL(2, "compressed size is %lu\n", totalCompressedSize); DISPLAYLEVEL(2, "compressed size is %lu\n", totalCompressedSize);
cRatio = (double)totalOriginalSize/(double)totalCompressedSize; cRatio = (double)totalOriginalSize/(double)totalCompressedSize;
_dictCleanup: _cleanup:
ZSTD_freeCDict(cdict);
_nodictCleanup:
free(dst); free(dst);
free(offsets); free(offsets);
ZSTD_freeCCtx(cctx); ZSTD_freeCCtx(cctx);
ZSTD_freeCDict(cdict);
return cRatio; return cRatio;
} }
@@ -249,7 +245,7 @@ int benchmarkDictBuilder(sampleInfo *srcInfo, unsigned maxDictSize, ZDICT_random
DISPLAYLEVEL(2, "%s took %f seconds to execute \n", name, timeSec); DISPLAYLEVEL(2, "%s took %f seconds to execute \n", name, timeSec);
/* Calculate compression ratio */ /* Calculate compression ratio */
double cRatio = compressWithDict(srcInfo, dInfo, cLevel, displayLevel); const double cRatio = compressWithDict(srcInfo, dInfo, cLevel, displayLevel);
if (cRatio < 0) { if (cRatio < 0) {
DISPLAYLEVEL(1, "Compressing with %s dictionary does not work\n", name); DISPLAYLEVEL(1, "Compressing with %s dictionary does not work\n", name);
result = 1; result = 1;