From c9bbad53ffda4a4f4595e3a2b6e3994710ee2324 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Fri, 3 Nov 2017 10:30:52 -0700 Subject: [PATCH] removed ctx->searchNum nbSearches now transmitted directly as function parameter easier to track and debug --- lib/lz4hc.c | 20 +++----------------- lib/lz4hc.h | 4 +--- lib/lz4opt.h | 14 ++++++++------ 3 files changed, 12 insertions(+), 26 deletions(-) diff --git a/lib/lz4hc.c b/lib/lz4hc.c index 643fbb2..a7577c5 100644 --- a/lib/lz4hc.c +++ b/lib/lz4hc.c @@ -640,17 +640,6 @@ _dest_overflow: return 0; } -static int LZ4HC_getSearchNum(int compressionLevel) -{ - assert(compressionLevel >= 1); - assert(compressionLevel <= LZ4HC_CLEVEL_MAX); - switch (compressionLevel) { - default: return 1 << (compressionLevel-1); - case 10: return 1 << 12; - case 11: return 512; - case 12: return 1<<13; - } -} static int LZ4HC_compress_generic ( LZ4HC_CCtx_internal* const ctx, @@ -667,16 +656,14 @@ static int LZ4HC_compress_generic ( if (limit == limitedDestSize) cLevel = 10; switch (cLevel) { case 10: - return LZ4HC_compress_hashChain(ctx, src, dst, srcSizePtr, dstCapacity, 1 << 12, limit); + return LZ4HC_compress_hashChain(ctx, src, dst, srcSizePtr, dstCapacity, 1<<12, limit); case 11: - ctx->searchNum = LZ4HC_getSearchNum(cLevel); - return LZ4HC_compress_optimal(ctx, src, dst, *srcSizePtr, dstCapacity, limit, 128, 0); + return LZ4HC_compress_optimal(ctx, src, dst, *srcSizePtr, dstCapacity, limit, 512, 128, 0); default: cLevel = 12; /* fall-through */ case 12: - ctx->searchNum = LZ4HC_getSearchNum(cLevel); - return LZ4HC_compress_optimal(ctx, src, dst, *srcSizePtr, dstCapacity, limit, LZ4_OPT_NUM, 1); + return LZ4HC_compress_optimal(ctx, src, dst, *srcSizePtr, dstCapacity, limit, 1<<13, LZ4_OPT_NUM, 1); } } return LZ4HC_compress_hashChain(ctx, src, dst, srcSizePtr, dstCapacity, 1 << (cLevel-1), limit); /* levels 1-9 */ @@ -741,7 +728,6 @@ void LZ4_resetStreamHC (LZ4_streamHC_t* LZ4_streamHCPtr, int compressionLevel) LZ4_streamHCPtr->internal_donotuse.base = NULL; if (compressionLevel > LZ4HC_CLEVEL_MAX) compressionLevel = LZ4HC_CLEVEL_MAX; /* cap compression level */ LZ4_streamHCPtr->internal_donotuse.compressionLevel = compressionLevel; - LZ4_streamHCPtr->internal_donotuse.searchNum = LZ4HC_getSearchNum(compressionLevel); } void LZ4_setCompressionLevel(LZ4_streamHC_t* LZ4_streamHCPtr, int compressionLevel) diff --git a/lib/lz4hc.h b/lib/lz4hc.h index 4fbe91e..13a0179 100644 --- a/lib/lz4hc.h +++ b/lib/lz4hc.h @@ -152,8 +152,7 @@ typedef struct uint32_t dictLimit; /* below that point, need extDict */ uint32_t lowLimit; /* below that point, no more dict */ uint32_t nextToUpdate; /* index from which to continue dictionary update */ - uint32_t searchNum; /* only for optimal parser */ - uint32_t compressionLevel; + int compressionLevel; } LZ4HC_CCtx_internal; #else @@ -169,7 +168,6 @@ typedef struct unsigned int dictLimit; /* below that point, need extDict */ unsigned int lowLimit; /* below that point, no more dict */ unsigned int nextToUpdate; /* index from which to continue dictionary update */ - unsigned int searchNum; /* only for optimal parser */ int compressionLevel; } LZ4HC_CCtx_internal; diff --git a/lib/lz4opt.h b/lib/lz4opt.h index 18bcd31..7aec7dd 100644 --- a/lib/lz4opt.h +++ b/lib/lz4opt.h @@ -91,11 +91,11 @@ int LZ4HC_FindLongerMatch(LZ4HC_CCtx_internal* const ctx, /* Index table will LZ4_FORCE_INLINE LZ4HC_match_t LZ4HC_HashChain_GetAllMatches (LZ4HC_CCtx_internal* const ctx, const BYTE* const ip, const BYTE* const iHighLimit, - size_t best_mlen) + size_t best_mlen, int nbSearches) { LZ4HC_match_t match = {0 , 0}; const BYTE* matchPtr = NULL; - int matchLength = LZ4HC_FindLongerMatch(ctx, ip, iHighLimit, (int)best_mlen, &matchPtr, ctx->searchNum); + int matchLength = LZ4HC_FindLongerMatch(ctx, ip, iHighLimit, (int)best_mlen, &matchPtr, nbSearches); if ((size_t)matchLength <= best_mlen) return match; match.len = matchLength; match.off = (int)(ip-matchPtr); @@ -110,8 +110,9 @@ static int LZ4HC_compress_optimal ( int inputSize, int dstCapacity, limitedOutput_directive limit, + int const nbSearches, size_t sufficient_len, - const int fullUpdate + int const fullUpdate ) { LZ4HC_optimal_t opt[LZ4_OPT_NUM + 3]; /* this uses a bit too much stack memory to my taste ... */ @@ -137,7 +138,7 @@ static int LZ4HC_compress_optimal ( int best_mlen, best_off; int cur, last_match_pos = 0; - LZ4HC_match_t const firstMatch = LZ4HC_HashChain_GetAllMatches(ctx, ip, matchlimit, MINMATCH-1); + LZ4HC_match_t const firstMatch = LZ4HC_HashChain_GetAllMatches(ctx, ip, matchlimit, MINMATCH-1, nbSearches); if (firstMatch.len==0) { ip++; continue; } if ((size_t)firstMatch.len > sufficient_len) { @@ -201,9 +202,10 @@ static int LZ4HC_compress_optimal ( DEBUGLOG(7, "search at rPos:%u", cur); if (fullUpdate) - newMatch = LZ4HC_HashChain_GetAllMatches(ctx, curPtr, matchlimit, MINMATCH-1); + newMatch = LZ4HC_HashChain_GetAllMatches(ctx, curPtr, matchlimit, MINMATCH-1, nbSearches); else - newMatch = LZ4HC_HashChain_GetAllMatches(ctx, curPtr, matchlimit, last_match_pos - cur); /* only test matches of a minimum length; slightly faster, but misses a few bytes */ + /* only test matches of minimum length; slightly faster, but misses a few bytes */ + newMatch = LZ4HC_HashChain_GetAllMatches(ctx, curPtr, matchlimit, last_match_pos - cur, nbSearches); if (!newMatch.len) continue; if ( ((size_t)newMatch.len > sufficient_len) -- 2.7.4