Merge pull request #1158 from lz4/fix1157 allocation optimization for lz4frame compression GitOrigin-RevId: 72997c5a915ccf80459cd023c6322239c308c025 Change-Id: Id5b7709af7560010999eaeab9f3c535a32094c87
diff --git a/lib/lz4frame.c b/lib/lz4frame.c index 174f9ae..b4caff4 100644 --- a/lib/lz4frame.c +++ b/lib/lz4frame.c
@@ -264,7 +264,7 @@ LZ4F_CustomMem cmem; LZ4F_preferences_t prefs; U32 version; - U32 cStage; + U32 cStage; /* 0 : compression uninitialized ; 1 : initialized, can compress */ const LZ4F_CDict* cdict; size_t maxBlockSize; size_t maxBufferSize; @@ -732,7 +732,7 @@ if (cctxPtr->maxBufferSize < requiredBuffSize) { cctxPtr->maxBufferSize = 0; LZ4F_free(cctxPtr->tmpBuff, cctxPtr->cmem); - cctxPtr->tmpBuff = (BYTE*)LZ4F_calloc(requiredBuffSize, cctxPtr->cmem); + cctxPtr->tmpBuff = (BYTE*)LZ4F_malloc(requiredBuffSize, cctxPtr->cmem); RETURN_ERROR_IF(cctxPtr->tmpBuff == NULL, allocation_failed); cctxPtr->maxBufferSize = requiredBuffSize; } } @@ -1176,7 +1176,6 @@ } cctxPtr->cStage = 0; /* state is now re-usable (with identical preferences) */ - cctxPtr->maxBufferSize = 0; /* reuse HC context */ if (cctxPtr->prefs.frameInfo.contentSize) { if (cctxPtr->prefs.frameInfo.contentSize != cctxPtr->totalInSize) @@ -1722,10 +1721,10 @@ /* history management (linked blocks only)*/ if (dctx->frameInfo.blockMode == LZ4F_blockLinked) { LZ4F_updateDict(dctx, dstPtr, sizeToCopy, dstStart, 0); - } } - - srcPtr += sizeToCopy; - dstPtr += sizeToCopy; + } + srcPtr += sizeToCopy; + dstPtr += sizeToCopy; + } if (sizeToCopy == dctx->tmpInTarget) { /* all done */ if (dctx->frameInfo.blockChecksumFlag) { dctx->tmpInSize = 0;
diff --git a/lib/lz4frame.h b/lib/lz4frame.h index 1bdf6c4..8d9380b 100644 --- a/lib/lz4frame.h +++ b/lib/lz4frame.h
@@ -278,7 +278,7 @@ /*! LZ4F_compressBegin() : * will write the frame header into dstBuffer. * dstCapacity must be >= LZ4F_HEADER_SIZE_MAX bytes. - * `prefsPtr` is optional : you can provide NULL as argument, all preferences will then be set to default. + * `prefsPtr` is optional : NULL can be provided to set all preferences to default. * @return : number of bytes written into dstBuffer for the header * or an error code (which can be tested using LZ4F_isError()) */