summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Collet <cyan@fb.com>2017-11-09 01:47:24 (GMT)
committerYann Collet <cyan@fb.com>2017-11-09 01:47:24 (GMT)
commit63f6039fb37bd561c776a1fc4eb04bd9ea46dc83 (patch)
tree59289bbd77073001ab19c50117f3ab222f0cf22a
parentf93b59571893f4ebf332c5d05e03b56f1359f46c (diff)
downloadlz4-63f6039fb37bd561c776a1fc4eb04bd9ea46dc83.zip
lz4-63f6039fb37bd561c776a1fc4eb04bd9ea46dc83.tar.gz
lz4-63f6039fb37bd561c776a1fc4eb04bd9ea46dc83.tar.bz2
added constant TRAILING_LITERALS
which is more explicit than its value `3`. reported by @terrelln
-rw-r--r--lib/lz4opt.h11
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/lz4opt.h b/lib/lz4opt.h
index 6db8586..7f74df9 100644
--- a/lib/lz4opt.h
+++ b/lib/lz4opt.h
@@ -105,7 +105,8 @@ static int LZ4HC_compress_optimal (
int const fullUpdate
)
{
- LZ4HC_optimal_t opt[LZ4_OPT_NUM + 3]; /* this uses a bit too much stack memory to my taste ... */
+#define TRAILING_LITERALS 3
+ LZ4HC_optimal_t opt[LZ4_OPT_NUM + TRAILING_LITERALS]; /* this uses a bit too much stack memory to my taste ... */
const BYTE* ip = (const BYTE*) source;
const BYTE* anchor = ip;
@@ -165,7 +166,7 @@ static int LZ4HC_compress_optimal (
} }
last_match_pos = firstMatch.len;
{ int addLit;
- for (addLit = 1; addLit <= 3; addLit ++) {
+ for (addLit = 1; addLit <= TRAILING_LITERALS; addLit ++) {
opt[last_match_pos+addLit].mlen = 1; /* literal */
opt[last_match_pos+addLit].off = 0;
opt[last_match_pos+addLit].litlen = addLit;
@@ -183,7 +184,7 @@ static int LZ4HC_compress_optimal (
DEBUGLOG(7, "rPos:%u[%u] vs [%u]%u",
cur, opt[cur].price, opt[cur+1].price, cur+1);
if (fullUpdate) {
- if ((opt[cur+1].price <= opt[cur].price) && (opt[cur+4].price < opt[cur].price+3)) continue;
+ if ((opt[cur+1].price <= opt[cur].price) && (opt[cur+MINMATCH].price < opt[cur].price + 3/*min seq price*/)) continue;
} else {
if (opt[cur+1].price <= opt[cur].price) continue;
}
@@ -241,7 +242,7 @@ static int LZ4HC_compress_optimal (
price = opt[cur].price + LZ4HC_sequencePrice(0, ml);
}
- if (pos > last_match_pos+3 || price <= opt[pos].price) {
+ if (pos > last_match_pos+TRAILING_LITERALS || price <= opt[pos].price) {
DEBUGLOG(7, "rPos:%3i => price:%3i (matchlen=%i)",
pos, price, ml);
assert(pos < LZ4_OPT_NUM);
@@ -255,7 +256,7 @@ static int LZ4HC_compress_optimal (
} } }
/* complete following positions with literals */
{ int addLit;
- for (addLit = 1; addLit <= 3; addLit ++) {
+ for (addLit = 1; addLit <= TRAILING_LITERALS; addLit ++) {
opt[last_match_pos+addLit].mlen = 1; /* literal */
opt[last_match_pos+addLit].off = 0;
opt[last_match_pos+addLit].litlen = addLit;