/* 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;
/* 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);
+ }
}
}
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)