summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Collet <cyan@fb.com>2016-11-10 23:31:59 (GMT)
committerYann Collet <cyan@fb.com>2016-11-10 23:31:59 (GMT)
commit1f246a98992fa7035823bedf6a0b7612fc290592 (patch)
tree2798ea12ec7cc812dfc5befbf9121939fc9d7938
parent5e13a6ec469e25c7dd425c7da4518b4ad2a8862d (diff)
downloadlz4-1f246a98992fa7035823bedf6a0b7612fc290592.zip
lz4-1f246a98992fa7035823bedf6a0b7612fc290592.tar.gz
lz4-1f246a98992fa7035823bedf6a0b7612fc290592.tar.bz2
Fixed #178 fullbench on small input
-rw-r--r--lib/lz4.c11
-rw-r--r--tests/fullbench.c4
2 files changed, 12 insertions, 3 deletions
diff --git a/lib/lz4.c b/lib/lz4.c
index 53b503c..f86e6f8 100644
--- a/lib/lz4.c
+++ b/lib/lz4.c
@@ -1066,10 +1066,17 @@ int LZ4_compress_forceExtDict (LZ4_stream_t* LZ4_dict, const char* source, char*
}
+/*! LZ4_saveDict() :
+ * If previously compressed data block is not guaranteed to remain available at its memory location,
+ * save it into a safer place (char* safeBuffer).
+ * Note : you don't need to call LZ4_loadDict() afterwards,
+ * dictionary is immediately usable, you can therefore call LZ4_compress_fast_continue().
+ * Return : saved dictionary size in bytes (necessarily <= dictSize), or 0 if error.
+ */
int LZ4_saveDict (LZ4_stream_t* LZ4_dict, char* safeBuffer, int dictSize)
{
- LZ4_stream_t_internal* dict = (LZ4_stream_t_internal*) LZ4_dict;
- const BYTE* previousDictEnd = dict->dictionary + dict->dictSize;
+ LZ4_stream_t_internal* const dict = (LZ4_stream_t_internal*) LZ4_dict;
+ const BYTE* const previousDictEnd = dict->dictionary + dict->dictSize;
if ((U32)dictSize > 64 KB) dictSize = 64 KB; /* useless to define a dictionary > 64 KB */
if ((U32)dictSize > dict->dictSize) dictSize = dict->dictSize;
diff --git a/tests/fullbench.c b/tests/fullbench.c
index 975cf8a..fa37fa6 100644
--- a/tests/fullbench.c
+++ b/tests/fullbench.c
@@ -386,7 +386,7 @@ static int local_LZ4_decompress_safe_partial(const char* in, char* out, int inSi
/* frame functions */
static int local_LZ4F_compressFrame(const char* in, char* out, int inSize)
{
- return (int)LZ4F_compressFrame(out, 2*inSize + 16, in, inSize, NULL);
+ return (int)LZ4F_compressFrame(out, LZ4F_compressFrameBound(inSize, NULL), in, inSize, NULL);
}
static LZ4F_decompressionContext_t g_dCtx;
@@ -532,9 +532,11 @@ int fullSpeedBench(const char** fileNamesTable, int nbFiles)
chunkP[0].origSize = (int)benchedSize; nbChunks=1;
break;
case 40: compressionFunction = local_LZ4_saveDict; compressorName = "LZ4_saveDict";
+ if (chunkP[0].origSize < 8) { DISPLAY(" cannot bench %s with less then 8 bytes \n", compressorName); continue; }
LZ4_loadDict(&LZ4_stream, chunkP[0].origBuffer, chunkP[0].origSize);
break;
case 41: compressionFunction = local_LZ4_saveDictHC; compressorName = "LZ4_saveDictHC";
+ if (chunkP[0].origSize < 8) { DISPLAY(" cannot bench %s with less then 8 bytes \n", compressorName); continue; }
LZ4_loadDictHC(&LZ4_streamHC, chunkP[0].origBuffer, chunkP[0].origSize);
break;
case 60: DISPLAY("Obsolete compression functions : \n"); continue;