Set Dictionary Context Pointer Rather than Copying the Context In

This commit is contained in:
W. Felix Handte 2018-02-12 12:19:13 -05:00
parent 73cc39327e
commit 68c6bd17b8
2 changed files with 42 additions and 10 deletions

View File

@ -1183,10 +1183,19 @@ int LZ4_compress_fast_continue (LZ4_stream_t* LZ4_stream, const char* source, ch
/* external dictionary mode */
{ int result;
if ((streamPtr->dictSize < 64 KB) && (streamPtr->dictSize < streamPtr->currentOffset))
result = LZ4_compress_generic(streamPtr, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, usingExtDict, dictSmall, acceleration);
else
result = LZ4_compress_generic(streamPtr, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, usingExtDict, noDictIssue, acceleration);
if ((streamPtr->dictSize < 64 KB) && (streamPtr->dictSize < streamPtr->currentOffset)) {
if (streamPtr->dictCtx) {
result = LZ4_compress_generic(streamPtr, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, usingExtDictCtx, dictSmall, acceleration);
} else {
result = LZ4_compress_generic(streamPtr, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, usingExtDict, dictSmall, acceleration);
}
} else {
if (streamPtr->dictCtx) {
result = LZ4_compress_generic(streamPtr, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, usingExtDictCtx, noDictIssue, acceleration);
} else {
result = LZ4_compress_generic(streamPtr, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, usingExtDict, noDictIssue, acceleration);
}
}
streamPtr->dictionary = (const BYTE*)source;
streamPtr->dictSize = (U32)inputSize;
return result;

View File

@ -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)