From 9c6fb8b160e72454cb50ca78ceca428cb246fd8a Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Thu, 23 Apr 2015 07:46:35 +0100 Subject: [PATCH] Added LZ4_compress_fast_extState() --- lib/lz4.c | 34 ++++++++++++++++++---------------- lib/lz4.h | 22 ++++++++++++---------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/lib/lz4.c b/lib/lz4.c index 490f9ce..e9fe467 100644 --- a/lib/lz4.c +++ b/lib/lz4.c @@ -697,29 +697,36 @@ int LZ4_compress_safe(const char* source, char* dest, int inputSize, int maxOutp } -int LZ4_compress_fast(const char* source, char* dest, int inputSize, int maxOutputSize, unsigned acceleration) +int LZ4_compress_fast_extState(void* state, const char* source, char* dest, int inputSize, int maxOutputSize, unsigned acceleration) { -#if (HEAPMODE) - void* ctx = ALLOCATOR(LZ4_STREAMSIZE_U64, 8); /* Aligned on 8-bytes boundaries */ -#else - U64 ctx[LZ4_STREAMSIZE_U64] = {0}; /* Ensure data is aligned on 8-bytes boundaries */ -#endif - int result; + MEM_INIT(state, 0, LZ4_STREAMSIZE); if (acceleration == 0) { if (inputSize < LZ4_64Klimit) - result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, ACCELERATION_DEFAULT); + return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, ACCELERATION_DEFAULT); else - result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limitedOutput, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, ACCELERATION_DEFAULT); + return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, ACCELERATION_DEFAULT); } else { if (inputSize < LZ4_64Klimit) - result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, acceleration); + return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, acceleration); else - result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limitedOutput, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, acceleration); + return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, acceleration); } +} + + +int LZ4_compress_fast(const char* source, char* dest, int inputSize, int maxOutputSize, unsigned acceleration) +{ +#if (HEAPMODE) + void* ctx = ALLOCATOR(LZ4_STREAMSIZE_U64, 8); /* Aligned on 8-bytes boundaries */ +#else + U64 ctx[LZ4_STREAMSIZE_U64]; /* Ensure data is aligned on 8-bytes boundaries */ +#endif + + int result = LZ4_compress_fast_extState(ctx, source, dest, inputSize, maxOutputSize, acceleration); #if (HEAPMODE) FREEMEM(ctx); @@ -740,11 +747,6 @@ LZ4_stream_t* LZ4_createStream(void) return lz4s; } -/* - * LZ4_initStream - * Use this function once, to init a newly allocated LZ4_stream_t structure - * Return : 1 if OK, 0 if error - */ void LZ4_resetStream (LZ4_stream_t* LZ4_stream) { MEM_INIT(LZ4_stream, 0, sizeof(LZ4_stream_t)); diff --git a/lib/lz4.h b/lib/lz4.h index cf06a8e..a2091fa 100644 --- a/lib/lz4.h +++ b/lib/lz4.h @@ -119,16 +119,6 @@ LZ4_compressBound() : int LZ4_compressBound(int inputSize); /* -LZ4_compress_fast() : - Same as LZ4_compress_limitedOutput, but allows to select an "acceleration" factor. - The larger the value, the faster the algorithm, but also the lesser the compression. - So it's a trade-off, which can be fine tuned, selecting whichever value you want. - An acceleration value of "0" means "use Default value", which is typically about 15 (see lz4.c source code). - Note : this function is "safe", even if its name does not say it. It's just faster and compress less. -*/ -int LZ4_compress_fast (const char* source, char* dest, int sourceSize, int maxOutputSize, unsigned acceleration); - -/* LZ4_compress_safe_extState() : Same compression function, just using an externally allocated memory space to store compression state. Use LZ4_sizeofState() to know how much memory must be allocated, @@ -138,6 +128,18 @@ LZ4_compress_safe_extState() : int LZ4_sizeofState(void); int LZ4_compress_safe_extState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize); +/* +LZ4_compress_fast() : + Same as LZ4_compress_safe(), but allows to select an "acceleration" factor. + The larger the acceleration value, the faster the algorithm, but also the lesser the compression. + It's a trade-off, which can be fine tuned, selecting whichever value you want. + An acceleration value of "0" means "use Default value", which is typically 17 (see lz4.c source code). + An acceleration value of "1" is the same as regular LZ4_compress_safe() + Note : this function is "safe", even if its name does not explicitly contain the word. It's just faster and compress less. +*/ +int LZ4_compress_fast (const char* source, char* dest, int sourceSize, int maxOutputSize, unsigned acceleration); +int LZ4_compress_fast_extState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize, unsigned acceleration); + /* LZ4_decompress_fast() : -- 2.7.4