summaryrefslogtreecommitdiffstats
path: root/lib/lz4frame.c
diff options
context:
space:
mode:
authorW. Felix Handte <w@felixhandte.com>2018-02-12 17:19:13 (GMT)
committerW. Felix Handte <w@felixhandte.com>2018-03-12 18:58:43 (GMT)
commit68c6bd17b82a0be501237af682f6472b0d39114f (patch)
tree1d0494ec607836b45ce3ccc4485c7e8d7fcf1f07 /lib/lz4frame.c
parent73cc39327e3abc28a360323c4f26c3c34d87ff07 (diff)
downloadlz4-68c6bd17b82a0be501237af682f6472b0d39114f.zip
lz4-68c6bd17b82a0be501237af682f6472b0d39114f.tar.gz
lz4-68c6bd17b82a0be501237af682f6472b0d39114f.tar.bz2
Set Dictionary Context Pointer Rather than Copying the Context In
Diffstat (limited to 'lib/lz4frame.c')
-rw-r--r--lib/lz4frame.c35
1 files changed, 29 insertions, 6 deletions
diff --git a/lib/lz4frame.c b/lib/lz4frame.c
index cd61925..9ff7766 100644
--- a/lib/lz4frame.c
+++ b/lib/lz4frame.c
@@ -571,16 +571,36 @@ size_t LZ4F_compressBegin_usingCDict(LZ4F_cctx* cctxPtr,
/* frame init only for blockLinked : blockIndependent will be init at each block */
if (cdict) {
if (cctxPtr->prefs.compressionLevel < LZ4HC_CLEVEL_MIN) {
- memcpy(cctxPtr->lz4CtxPtr, cdict->fastCtx, sizeof(*cdict->fastCtx));
+ LZ4_stream_t_internal* internal_ctx = &((LZ4_stream_t*)cctxPtr->lz4CtxPtr)->internal_donotuse;
+ assert(!internal_ctx->initCheck);
+ if (internal_ctx->currentOffset > 1 GB) {
+ /* Init the context */
+ LZ4_resetStream((LZ4_stream_t*)cctxPtr->lz4CtxPtr);
+ }
+ /* Clear any local dictionary */
+ internal_ctx->dictionary = NULL;
+ internal_ctx->dictSize = 0;
+ /* Point to the dictionary context */
+ internal_ctx->dictCtx = &(cdict->fastCtx->internal_donotuse);
} else {
memcpy(cctxPtr->lz4CtxPtr, cdict->HCCtx, sizeof(*cdict->HCCtx));
LZ4_setCompressionLevel((LZ4_streamHC_t*)cctxPtr->lz4CtxPtr, cctxPtr->prefs.compressionLevel);
}
} else {
- if (cctxPtr->prefs.compressionLevel < LZ4HC_CLEVEL_MIN)
- LZ4_resetStream((LZ4_stream_t*)(cctxPtr->lz4CtxPtr));
- else
+ if (cctxPtr->prefs.compressionLevel < LZ4HC_CLEVEL_MIN) {
+ LZ4_stream_t_internal* internal_ctx = &((LZ4_stream_t*)cctxPtr->lz4CtxPtr)->internal_donotuse;
+ assert(!internal_ctx->initCheck);
+ if (internal_ctx->currentOffset > 1 GB) {
+ /* Init the context */
+ LZ4_resetStream((LZ4_stream_t*)cctxPtr->lz4CtxPtr);
+ }
+ /* Clear any local dictionary */
+ internal_ctx->dictionary = NULL;
+ internal_ctx->dictSize = 0;
+ internal_ctx->dictCtx = NULL;
+ } else {
LZ4_resetStreamHC((LZ4_streamHC_t*)(cctxPtr->lz4CtxPtr), cctxPtr->prefs.compressionLevel);
+ }
}
}
@@ -686,10 +706,13 @@ static int LZ4F_compressBlock(void* ctx, const char* src, char* dst, int srcSize
internal_ctx->dictionary = NULL;
internal_ctx->dictSize = 0;
if (cdict) {
- memcpy(ctx, cdict->fastCtx, sizeof(*cdict->fastCtx));
+ /* Point to the dictionary context */
+ internal_ctx->dictCtx = &(cdict->fastCtx->internal_donotuse);
return LZ4_compress_fast_continue((LZ4_stream_t*)ctx, src, dst, srcSize, dstCapacity, acceleration);
+ } else {
+ internal_ctx->dictCtx = NULL;
+ return LZ4_compress_fast_safeExtState(ctx, src, dst, srcSize, dstCapacity, acceleration);
}
- return LZ4_compress_fast_safeExtState(ctx, src, dst, srcSize, dstCapacity, acceleration);
}
static int LZ4F_compressBlock_continue(void* ctx, const char* src, char* dst, int srcSize, int dstCapacity, int level, const LZ4F_CDict* cdict)