summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorYann Collet <cyan@fb.com>2017-11-03 09:01:20 (GMT)
committerYann Collet <cyan@fb.com>2017-11-03 09:03:19 (GMT)
commite2eca62046e500a95ab34e913e939aa68acb2cd4 (patch)
tree2093a20c1fcd451c7c8f1e80e22087c3b1e3090b /lib
parent3b222d2d963fe6144498a3cb306943566ddb6922 (diff)
downloadlz4-e2eca62046e500a95ab34e913e939aa68acb2cd4.zip
lz4-e2eca62046e500a95ab34e913e939aa68acb2cd4.tar.gz
lz4-e2eca62046e500a95ab34e913e939aa68acb2cd4.tar.bz2
LZ4_compress_HC_continue_destSize() now compatible with optimal parser
levels 11+
Diffstat (limited to 'lib')
-rw-r--r--lib/lz4hc.c11
-rw-r--r--lib/lz4hc.h4
-rw-r--r--lib/lz4opt.h10
3 files changed, 13 insertions, 12 deletions
diff --git a/lib/lz4hc.c b/lib/lz4hc.c
index c1f8da6..643fbb2 100644
--- a/lib/lz4hc.c
+++ b/lib/lz4hc.c
@@ -642,8 +642,11 @@ _dest_overflow:
static int LZ4HC_getSearchNum(int compressionLevel)
{
+ assert(compressionLevel >= 1);
+ assert(compressionLevel <= LZ4HC_CLEVEL_MAX);
switch (compressionLevel) {
- default: return 0; /* unused */
+ default: return 1 << (compressionLevel-1);
+ case 10: return 1 << 12;
case 11: return 512;
case 12: return 1<<13;
}
@@ -709,8 +712,7 @@ int LZ4_compress_HC(const char* src, char* dst, int srcSize, int dstCapacity, in
}
/* LZ4_compress_HC_destSize() :
- * currently, only compatible with Hash Chain implementation,
- * hence limit compression level to LZ4HC_CLEVEL_OPT_MIN-1*/
+ * only compatible with Hash Chain match finder */
int LZ4_compress_HC_destSize(void* LZ4HC_Data, const char* source, char* dest, int* sourceSizePtr, int targetDestSize, int cLevel)
{
LZ4HC_CCtx_internal* const ctx = &((LZ4_streamHC_t*)LZ4HC_Data)->internal_donotuse;
@@ -744,6 +746,7 @@ void LZ4_resetStreamHC (LZ4_streamHC_t* LZ4_streamHCPtr, int compressionLevel)
void LZ4_setCompressionLevel(LZ4_streamHC_t* LZ4_streamHCPtr, int compressionLevel)
{
+ /* note : 1-10 / 11-12 separation might no longer be necessary since optimal parser uses hash chain too */
int const currentCLevel = LZ4_streamHCPtr->internal_donotuse.compressionLevel;
int const minCLevel = currentCLevel < LZ4HC_CLEVEL_OPT_MIN ? 1 : LZ4HC_CLEVEL_OPT_MIN;
int const maxCLevel = currentCLevel < LZ4HC_CLEVEL_OPT_MIN ? LZ4HC_CLEVEL_OPT_MIN-1 : LZ4HC_CLEVEL_MAX;
@@ -824,8 +827,6 @@ int LZ4_compress_HC_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* src,
int LZ4_compress_HC_continue_destSize (LZ4_streamHC_t* LZ4_streamHCPtr, const char* src, char* dst, int* srcSizePtr, int targetDestSize)
{
- LZ4HC_CCtx_internal* const ctxPtr = &LZ4_streamHCPtr->internal_donotuse;
- if (ctxPtr->compressionLevel >= LZ4HC_CLEVEL_OPT_MIN) LZ4HC_init(ctxPtr, (const BYTE*)src); /* not compatible with btopt implementation */
return LZ4_compressHC_continue_generic(LZ4_streamHCPtr, src, dst, srcSizePtr, targetDestSize, limitedDestSize);
}
diff --git a/lib/lz4hc.h b/lib/lz4hc.h
index 191ab0c..4fbe91e 100644
--- a/lib/lz4hc.h
+++ b/lib/lz4hc.h
@@ -266,8 +266,8 @@ int LZ4_compress_HC_continue_destSize(LZ4_streamHC_t* LZ4_streamHCPtr,
int* srcSizePtr, int targetDstSize);
/*! LZ4_setCompressionLevel() : v1.8.0 (experimental)
- * It's possible to change compression level after LZ4_resetStreamHC(), between 2 invocations of LZ4_compress_HC_continue*(),
- * but that requires to stay in the same mode (aka 1-10 or 11-12).
+ * It's possible to change compression level between 2 invocations of LZ4_compress_HC_continue*(),
+ * but it requires to stay in the same mode (aka 1-10 or 11-12).
* This function ensures this condition.
*/
void LZ4_setCompressionLevel(LZ4_streamHC_t* LZ4_streamHCPtr, int compressionLevel);
diff --git a/lib/lz4opt.h b/lib/lz4opt.h
index a1627f1..18bcd31 100644
--- a/lib/lz4opt.h
+++ b/lib/lz4opt.h
@@ -160,7 +160,7 @@ static int LZ4HC_compress_optimal (
DEBUGLOG(7, "rPos:%3i => price:%3i (litlen=%i) -- initial setup",
rPos, cost, opt[rPos].litlen);
} }
- /* set prices using matches found for rPos = 0 */
+ /* set prices using initial match */
{ int mlen = MINMATCH;
int const matchML = firstMatch.len; /* necessarily < sufficient_len < LZ4_OPT_NUM */
int const offset = firstMatch.off;
@@ -215,7 +215,7 @@ static int LZ4HC_compress_optimal (
goto encode;
}
- /* before first match : set price with literals at beginning */
+ /* before match : set price with literals at beginning */
{ int const baseLitlen = opt[cur].litlen;
int litlen;
for (litlen = 1; litlen < MINMATCH; litlen++) {
@@ -230,10 +230,10 @@ static int LZ4HC_compress_optimal (
pos, price, opt[pos].litlen);
} } }
- /* set prices using matches at position = cur */
+ /* set prices using match at position = cur */
{ int const matchML = newMatch.len;
int ml = MINMATCH;
-
+
assert(cur + newMatch.len < LZ4_OPT_NUM);
for ( ; ml <= matchML ; ml++) {
int const pos = cur + ml;
@@ -255,7 +255,7 @@ static int LZ4HC_compress_optimal (
DEBUGLOG(7, "rPos:%3i => price:%3i (matchlen=%i)",
pos, price, ml);
assert(pos < LZ4_OPT_NUM);
- if ( (ml == matchML) /* last post of last match */
+ if ( (ml == matchML) /* last pos of last match */
&& (last_match_pos < pos) )
last_match_pos = pos;
opt[pos].mlen = ml;