mirror of
https://github.com/lz4/lz4.git
synced 2024-11-28 12:25:20 +08:00
unified HC levels
LZ4_setCompressionLevel() can be users accross the whole range of HC levels No more transition issue between Optimal and HC modes
This commit is contained in:
parent
a1f4a0d983
commit
1025546347
12
lib/lz4hc.c
12
lib/lz4hc.c
@ -49,6 +49,7 @@
|
||||
|
||||
|
||||
/*=== Dependency ===*/
|
||||
#define LZ4_HC_STATIC_LINKING_ONLY
|
||||
#include "lz4hc.h"
|
||||
|
||||
|
||||
@ -726,18 +727,13 @@ void LZ4_resetStreamHC (LZ4_streamHC_t* LZ4_streamHCPtr, int compressionLevel)
|
||||
{
|
||||
LZ4_STATIC_ASSERT(sizeof(LZ4HC_CCtx_internal) <= sizeof(size_t) * LZ4_STREAMHCSIZE_SIZET); /* if compilation fails here, LZ4_STREAMHCSIZE must be increased */
|
||||
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_setCompressionLevel(LZ4_streamHCPtr, 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;
|
||||
compressionLevel = MIN(compressionLevel, minCLevel);
|
||||
compressionLevel = MAX(compressionLevel, maxCLevel);
|
||||
if (compressionLevel < 1) compressionLevel = 1;
|
||||
if (compressionLevel > LZ4HC_CLEVEL_MAX) compressionLevel = LZ4HC_CLEVEL_MAX;
|
||||
LZ4_streamHCPtr->internal_donotuse.compressionLevel = compressionLevel;
|
||||
}
|
||||
|
||||
|
@ -265,8 +265,7 @@ int LZ4_compress_HC_continue_destSize(LZ4_streamHC_t* LZ4_streamHCPtr,
|
||||
|
||||
/*! LZ4_setCompressionLevel() : v1.8.0 (experimental)
|
||||
* 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.
|
||||
* though it requires to stay in the same mode (aka fast or HC).
|
||||
*/
|
||||
void LZ4_setCompressionLevel(LZ4_streamHC_t* LZ4_streamHCPtr, int compressionLevel);
|
||||
|
||||
|
@ -376,9 +376,9 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
|
||||
FUZ_CHECKTEST(ret<0, "LZ4_decompress_safe() failed on data compressed by LZ4_compressHC_destSize");
|
||||
FUZ_CHECKTEST(ret!=srcSize, "LZ4_decompress_safe() failed : did not fully decompressed data");
|
||||
FUZ_CHECKTEST(decodedBuffer[srcSize] != canary, "LZ4_decompress_safe() overwrite dst buffer !");
|
||||
{ U32 const crcDec = XXH32(decodedBuffer, srcSize, 0);
|
||||
FUZ_CHECKTEST(crcDec!=crcBase, "LZ4_decompress_safe() corrupted decoded data"); }
|
||||
|
||||
{ U32 const crcDec = XXH32(decodedBuffer, srcSize, 0);
|
||||
FUZ_CHECKTEST(crcDec!=crcBase, "LZ4_decompress_safe() corrupted decoded data");
|
||||
}
|
||||
DISPLAYLEVEL(5, " OK \n");
|
||||
}
|
||||
else
|
||||
@ -460,8 +460,7 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
|
||||
|
||||
// Test decoding with output size being 10 bytes too short => must fail
|
||||
FUZ_DISPLAYTEST;
|
||||
if (blockSize>10)
|
||||
{
|
||||
if (blockSize>10) {
|
||||
decodedBuffer[blockSize-10] = 0;
|
||||
ret = LZ4_decompress_safe(compressedBuffer, decodedBuffer, compressedSize, blockSize-10);
|
||||
FUZ_CHECKTEST(ret>=0, "LZ4_decompress_safe should have failed, due to Output Size being 10 bytes too short");
|
||||
@ -632,6 +631,7 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
|
||||
if (dict < (char*)CNBuffer) dict = (char*)CNBuffer;
|
||||
LZ4_resetStreamHC (&LZ4dictHC, compressionLevel);
|
||||
LZ4_loadDictHC(&LZ4dictHC, dict, dictSize);
|
||||
LZ4_setCompressionLevel(&LZ4dictHC, compressionLevel-1);
|
||||
blockContinueCompressedSize = LZ4_compress_HC_continue(&LZ4dictHC, block, compressedBuffer, blockSize, (int)compressedBufferSize);
|
||||
FUZ_CHECKTEST(blockContinueCompressedSize==0, "LZ4_compress_HC_continue failed");
|
||||
|
||||
@ -657,7 +657,7 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
|
||||
FUZ_CHECKTEST(crcCheck!=crcOrig, "LZ4_decompress_safe_usingDict corrupted decoded data");
|
||||
|
||||
/* Compress HC continue destSize */
|
||||
FUZ_DISPLAYTEST;
|
||||
FUZ_DISPLAYTEST;
|
||||
{ int const availableSpace = (FUZ_rand(&randState) % blockSize) + 5;
|
||||
int consumedSize = blockSize;
|
||||
FUZ_DISPLAYTEST;
|
||||
|
Loading…
Reference in New Issue
Block a user