From 4f050b68d817776e3c1fac6c449b5f2b2adfbcb9 Mon Sep 17 00:00:00 2001 From: Przemyslaw Skibinski Date: Fri, 9 Dec 2016 18:17:46 +0100 Subject: tree update dependent from compression level --- lib/lz4hc.c | 6 ++++-- lib/lz4hc.h | 1 + lib/lz4opt.h | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/lz4hc.c b/lib/lz4hc.c index e1eadf7..44a1340 100644 --- a/lib/lz4hc.c +++ b/lib/lz4hc.c @@ -574,8 +574,10 @@ int LZ4_loadDictHC (LZ4_streamHC_t* LZ4_streamHCPtr, const char* dictionary, int static void LZ4HC_setExternalDict(LZ4HC_CCtx_internal* ctxPtr, const BYTE* newBlock) { - if (ctxPtr->end >= ctxPtr->base + 4) LZ4HC_Insert (ctxPtr, ctxPtr->end-3); /* Referencing remaining dictionary content */ - LZ4HC_updateBinTree(ctxPtr, ctxPtr->end - MFLIMIT, ctxPtr->end - LASTLITERALS); + if (ctxPtr->compressionLevel >= LZ4HC_MIN_CLEVEL_OPT) + LZ4HC_updateBinTree(ctxPtr, ctxPtr->end - MFLIMIT, ctxPtr->end - LASTLITERALS); + else + if (ctxPtr->end >= ctxPtr->base + 4) LZ4HC_Insert (ctxPtr, ctxPtr->end-3); /* Referencing remaining dictionary content */ /* Only one memory segment for extDict, so any previous extDict is lost at this stage */ ctxPtr->lowLimit = ctxPtr->dictLimit; diff --git a/lib/lz4hc.h b/lib/lz4hc.h index a3736f8..7ce5958 100644 --- a/lib/lz4hc.h +++ b/lib/lz4hc.h @@ -46,6 +46,7 @@ extern "C" { /* --- Useful constants --- */ #define LZ4HC_MIN_CLEVEL 3 #define LZ4HC_DEFAULT_CLEVEL 9 +#define LZ4HC_MIN_CLEVEL_OPT 11 #define LZ4HC_MAX_CLEVEL 12 diff --git a/lib/lz4opt.h b/lib/lz4opt.h index 0844f8e..f487edf 100644 --- a/lib/lz4opt.h +++ b/lib/lz4opt.h @@ -36,7 +36,7 @@ #define LZ4_LOG_PARSER(fmt, ...) //printf(fmt, __VA_ARGS__) #define LZ4_LOG_PRICE(fmt, ...) //printf(fmt, __VA_ARGS__) #define LZ4_LOG_ENCODE(fmt, ...) //printf(fmt, __VA_ARGS__) -#include + #define LZ4_OPT_NUM (1<<12) @@ -189,7 +189,7 @@ FORCE_INLINE int LZ4HC_BinTree_GetAllMatches ( if (ip < ctx->base + ctx->nextToUpdateBT) return 0; /* skipped area */ if (fullUpdate) LZ4HC_updateBinTree(ctx, ip, iHighLimit); best_mlen = LZ4HC_BinTree_InsertAndGetAllMatches(ctx, ip, iHighLimit, best_mlen, matches, &mnum); - ctx->nextToUpdateBT = (U32)(ip - ctx->base) + best_mlen; + ctx->nextToUpdateBT = (U32)(ip - ctx->base + best_mlen); return mnum; } -- cgit v0.12