diff options
author | Jennifer Liu <jenniferliu620@fb.com> | 2018-06-27 20:36:38 (GMT) |
---|---|---|
committer | Jennifer Liu <jenniferliu620@fb.com> | 2018-06-27 20:36:38 (GMT) |
commit | e778db373b67ce15311b783c49b1d054293ce2af (patch) | |
tree | 0a5093a3eb5a14c55b40bde4f8eb6c379522f257 | |
parent | 8745638d7c04bdfc33bcf656ed262c2588534db5 (diff) | |
download | lz4-e778db373b67ce15311b783c49b1d054293ce2af.zip lz4-e778db373b67ce15311b783c49b1d054293ce2af.tar.gz lz4-e778db373b67ce15311b783c49b1d054293ce2af.tar.bz2 |
Fixed bugs about incorrect acceleration calculation and benchmarking negative compresion level
-rw-r--r-- | lib/lz4frame.c | 4 | ||||
-rw-r--r-- | programs/bench.c | 5 | ||||
-rw-r--r-- | tests/Makefile | 3 |
3 files changed, 7 insertions, 5 deletions
diff --git a/lib/lz4frame.c b/lib/lz4frame.c index e1d0b1d..08bf0fa 100644 --- a/lib/lz4frame.c +++ b/lib/lz4frame.c @@ -738,7 +738,7 @@ static size_t LZ4F_makeBlock(void* dst, const void* src, size_t srcSize, static int LZ4F_compressBlock(void* ctx, const char* src, char* dst, int srcSize, int dstCapacity, int level, const LZ4F_CDict* cdict) { - int const acceleration = (level < -1) ? -level : 1; + int const acceleration = (level < 0) ? -level + 1 : 1; LZ4F_initStream(ctx, cdict, level, LZ4F_blockIndependent); if (cdict) { return LZ4_compress_fast_continue((LZ4_stream_t*)ctx, src, dst, srcSize, dstCapacity, acceleration); @@ -749,7 +749,7 @@ static int LZ4F_compressBlock(void* ctx, const char* src, char* dst, int srcSize static int LZ4F_compressBlock_continue(void* ctx, const char* src, char* dst, int srcSize, int dstCapacity, int level, const LZ4F_CDict* cdict) { - int const acceleration = (level < -1) ? -level : 1; + int const acceleration = (level < 0) ? -level + 1 : 1; (void)cdict; /* init once at beginning of frame */ return LZ4_compress_fast_continue((LZ4_stream_t*)ctx, src, dst, srcSize, dstCapacity, acceleration); } diff --git a/programs/bench.c b/programs/bench.c index 770191c..9dc31c4 100644 --- a/programs/bench.c +++ b/programs/bench.c @@ -49,7 +49,10 @@ #include "lz4.h" #define COMPRESSOR0 LZ4_compress_local -static int LZ4_compress_local(const char* src, char* dst, int srcSize, int dstSize, int clevel) { (void)clevel; return LZ4_compress_default(src, dst, srcSize, dstSize); } +static int LZ4_compress_local(const char* src, char* dst, int srcSize, int dstSize, int clevel) { + int const acceleration = (clevel < 0) ? -clevel + 1 : 1; + return LZ4_compress_fast(src, dst, srcSize, dstSize, acceleration); +} #include "lz4hc.h" #define COMPRESSOR1 LZ4_compress_HC #define DEFAULTCOMPRESSOR COMPRESSOR0 diff --git a/tests/Makefile b/tests/Makefile index 0e7924a..81033b5 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -265,9 +265,8 @@ test-lz4-basic: lz4 datagen unlz4 lz4cat # ./datagen -g20KB generates the same file every single time # cannot save output of ./datagen -g20KB as input file to lz4 because the following shell commands are run before ./datagen -g20KB test "$(shell ./datagen -g20KB | $(LZ4) -c --fast | wc -c)" -lt "$(shell ./datagen -g20KB | $(LZ4) -c --fast=9 | wc -c)" # -1 vs -9 + test "$(shell ./datagen -g20KB | $(LZ4) -c -1 | wc -c)" -lt "$(shell ./datagen -g20KB| $(LZ4) -c --fast=1 | wc -c)" # 1 vs -1 test "$(shell ./datagen -g20KB | $(LZ4) -c --fast=1 | wc -c)" -eq "$(shell ./datagen -g20KB| $(LZ4) -c --fast| wc -c)" # checks default fast compression is -1 - test "$(shell ./datagen -g20KB | $(LZ4) -c -3 | wc -c)" -lt "$(shell ./datagen -g20KB| $(LZ4) -c --fast=1 | wc -c)" # 3 vs -1 - test "$(shell ./datagen -g20KB | $(LZ4) -c -1 | wc -c)" -lt "$(shell ./datagen -g20KB| $(LZ4) -c --fast=2 | wc -c)" # 1 vs -2 ! $(LZ4) -c --fast=0 tmp-tlb-dg20K # lz4 should fail when fast=0 ! $(LZ4) -c --fast=-1 tmp-tlb-dg20K # lz4 should fail when fast=-1 @$(RM) tmp-tlb* |