diff options
author | Yann Collet <Cyan4973@users.noreply.github.com> | 2018-05-03 22:37:51 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-03 22:37:51 (GMT) |
commit | f3e84ffd41bb3ff10756efcf3334493639e0b395 (patch) | |
tree | 8b353f3c1548c982e1e750a07a9559d96923689f /lib/lz4frame.c | |
parent | 2b6c4f3d6367bf3f8bc38358109ab0a1b1d7340b (diff) | |
parent | 5406c2e479f5bb2b594a43e74e28719f4640450f (diff) | |
download | lz4-f3e84ffd41bb3ff10756efcf3334493639e0b395.zip lz4-f3e84ffd41bb3ff10756efcf3334493639e0b395.tar.gz lz4-f3e84ffd41bb3ff10756efcf3334493639e0b395.tar.bz2 |
Merge pull request #529 from felixhandte/lz4f-fast-reset-for-streaming-only
LZ4F: Only Reset the LZ4_stream_t when Init'ing a Streaming Block
Diffstat (limited to 'lib/lz4frame.c')
-rw-r--r-- | lib/lz4frame.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/lib/lz4frame.c b/lib/lz4frame.c index f57db24..aa7889b 100644 --- a/lib/lz4frame.c +++ b/lib/lz4frame.c @@ -551,9 +551,18 @@ LZ4F_errorCode_t LZ4F_freeCompressionContext(LZ4F_compressionContext_t LZ4F_comp */ static void LZ4F_initStream(void* ctx, const LZ4F_CDict* cdict, - int level) { + int level, + LZ4F_blockMode_t blockMode) { if (level < LZ4HC_CLEVEL_MIN) { - LZ4_resetStream_fast((LZ4_stream_t *)ctx); + if (cdict != NULL || blockMode == LZ4F_blockLinked) { + /* In these cases, we will call LZ4_compress_fast_continue(), + * which needs an already reset context. Otherwise, we'll call a + * one-shot API. The non-continued APIs internally perform their own + * resets at the beginning of their calls, where they know what + * tableType they need the context to be in. So in that case this + * would be misguided / wasted work. */ + LZ4_resetStream_fast((LZ4_stream_t*)ctx); + } LZ4_attach_dictionary((LZ4_stream_t *)ctx, cdict ? cdict->fastCtx : NULL); } else { LZ4_resetStreamHC_fast((LZ4_streamHC_t*)ctx, level); @@ -631,7 +640,7 @@ size_t LZ4F_compressBegin_usingCDict(LZ4F_cctx* cctxPtr, cctxPtr->cdict = cdict; if (cctxPtr->prefs.frameInfo.blockMode == LZ4F_blockLinked) { /* frame init only for blockLinked : blockIndependent will be init at each block */ - LZ4F_initStream(cctxPtr->lz4CtxPtr, cdict, cctxPtr->prefs.compressionLevel); + LZ4F_initStream(cctxPtr->lz4CtxPtr, cdict, cctxPtr->prefs.compressionLevel, LZ4F_blockLinked); } if (preferencesPtr->compressionLevel >= LZ4HC_CLEVEL_MIN) { LZ4_favorDecompressionSpeed((LZ4_streamHC_t*)cctxPtr->lz4CtxPtr, (int)preferencesPtr->favorDecSpeed); @@ -729,7 +738,7 @@ static size_t LZ4F_makeBlock(void* dst, const void* src, size_t srcSize, static int LZ4F_compressBlock(void* ctx, const char* src, char* dst, int srcSize, int dstCapacity, int level, const LZ4F_CDict* cdict) { int const acceleration = (level < -1) ? -level : 1; - LZ4F_initStream(ctx, cdict, level); + LZ4F_initStream(ctx, cdict, level, LZ4F_blockIndependent); if (cdict) { return LZ4_compress_fast_continue((LZ4_stream_t*)ctx, src, dst, srcSize, dstCapacity, acceleration); } else { @@ -746,7 +755,7 @@ static int LZ4F_compressBlock_continue(void* ctx, const char* src, char* dst, in static int LZ4F_compressBlockHC(void* ctx, const char* src, char* dst, int srcSize, int dstCapacity, int level, const LZ4F_CDict* cdict) { - LZ4F_initStream(ctx, cdict, level); + LZ4F_initStream(ctx, cdict, level, LZ4F_blockIndependent); if (cdict) { return LZ4_compress_HC_continue((LZ4_streamHC_t*)ctx, src, dst, srcSize, dstCapacity); } |