aboutsummaryrefslogtreecommitdiff
path: root/lib/lz4hc.c
diff options
context:
space:
mode:
authorYann Collet <cyan@fb.com>2017-11-02 13:44:57 -0700
committerYann Collet <cyan@fb.com>2017-11-02 13:44:57 -0700
commit0ff4df1b941145d5b728b4b4a936391537b8ea11 (patch)
treed0ce5b54e4bb0d3d6929c2b4cd5ff750102e0115 /lib/lz4hc.c
parent15b0d229c1d4a040d63f814c31a2a025145f29c7 (diff)
downloadlz4-0ff4df1b941145d5b728b4b4a936391537b8ea11.tar.gz
changed strategy : opt[] path is complete after each match
previous strategy would leave a few "bad choices" on the ground they would be fixed later, but that requires passing through each position to make the fix and cannot give the end position of the last useful match.
Diffstat (limited to 'lib/lz4hc.c')
-rw-r--r--lib/lz4hc.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/lib/lz4hc.c b/lib/lz4hc.c
index 4532ba3d..eb31a9c8 100644
--- a/lib/lz4hc.c
+++ b/lib/lz4hc.c
@@ -342,10 +342,6 @@ typedef enum {
limitedDestSize = 2,
} limitedOutput_directive;
-#ifndef LZ4HC_DEBUG
-# define LZ4HC_DEBUG 0
-#endif
-
/* LZ4HC_encodeSequence() :
* @return : 0 if ok,
* 1 if buffer issue detected */
@@ -361,9 +357,19 @@ LZ4_FORCE_INLINE int LZ4HC_encodeSequence (
size_t length;
BYTE* const token = (*op)++;
-#if LZ4HC_DEBUG
- printf("literal : %u -- match : %u -- offset : %u\n",
- (U32)(*ip - *anchor), (U32)matchLength, (U32)(*ip-match));
+#if defined(LZ4_DEBUG) && (LZ4_DEBUG >= 2)
+ static const BYTE* start = NULL;
+ static U32 totalCost = 0;
+ U32 const ll = (U32)(*ip - *anchor);
+ U32 const llAdd = (ll>=15) ? ((ll-15) / 255) + 1 : 0;
+ U32 const mlAdd = (matchLength>=19) ? ((matchLength-19) / 255) + 1 : 0;
+ U32 const cost = 1 + llAdd + ll + 2 + mlAdd;
+ if (start==NULL) start = *anchor; /* only works for single segment */
+ totalCost += cost;
+ DEBUGLOG(2, "pos:%7u -- literals:%3u, match:%4i, offset:%5u, cost:%3u/%7u",
+ (U32)(*anchor - start),
+ (U32)(*ip - *anchor), matchLength, (U32)(*ip-match),
+ cost, totalCost);
#endif
/* Encode Literal length */
@@ -386,6 +392,7 @@ LZ4_FORCE_INLINE int LZ4HC_encodeSequence (
LZ4_writeLE16(*op, (U16)(*ip-match)); *op += 2;
/* Encode MatchLength */
+ assert(matchLength >= MINMATCH);
length = (size_t)(matchLength - MINMATCH);
if ((limit) && (*op + (length >> 8) + (1 + LASTLITERALS) > oend)) return 1; /* Check output limit */
if (length >= ML_MASK) {