diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/lz4.c | 6 | ||||
-rw-r--r-- | lib/lz4hc.c | 39 |
2 files changed, 31 insertions, 14 deletions
@@ -238,7 +238,7 @@ static void LZ4_writeLE16(void* memPtr, U16 value) static void LZ4_copy8(void* dst, const void* src) { - memcpy(dst,src,8); + memcpy(dst,src,8); } /* customized variant of memcpy, which can overwrite up to 7 bytes beyond dstEnd */ @@ -248,11 +248,11 @@ static void LZ4_wildCopy(void* dstPtr, const void* srcPtr, void* dstEnd) const BYTE* s = (const BYTE*)srcPtr; BYTE* const e = (BYTE*)dstEnd; -#if 1 +#if 0 const size_t l2 = 8 - (((size_t)d) & (sizeof(void*)-1)); LZ4_copy8(d,s); if (d>e-9) return; d+=l2; s+=l2; -#endif // join to align +#endif /* join to align */ do { LZ4_copy8(d,s); d+=8; s+=8; } while (d<e); } diff --git a/lib/lz4hc.c b/lib/lz4hc.c index bbe7a9d..80bfa39 100644 --- a/lib/lz4hc.c +++ b/lib/lz4hc.c @@ -34,21 +34,29 @@ -/************************************** +/* ************************************* * Tuning Parameter -**************************************/ +***************************************/ static const int LZ4HC_compressionLevel_default = 9; +/*! + * HEAPMODE : + * Select how default compression function will allocate workplace memory, + * in stack (0:fastest), or in heap (1:requires malloc()). + * Since workplace is rather large, heap mode is recommended. + */ +#define LZ4HC_HEAPMODE 0 -/************************************** + +/* ************************************* * Includes -**************************************/ +***************************************/ #include "lz4hc.h" -/************************************** +/* ************************************* * Local Compiler Options -**************************************/ +***************************************/ #if defined(__GNUC__) # pragma GCC diagnostic ignored "-Wunused-function" #endif @@ -58,16 +66,16 @@ static const int LZ4HC_compressionLevel_default = 9; #endif -/************************************** +/* ************************************* * Common LZ4 definition -**************************************/ +***************************************/ #define LZ4_COMMONDEFS_ONLY #include "lz4.c" -/************************************** +/* ************************************* * Local Constants -**************************************/ +***************************************/ #define DICTIONARY_LOGSIZE 16 #define MAXD (1<<DICTIONARY_LOGSIZE) #define MAXD_MASK (MAXD - 1) @@ -549,8 +557,17 @@ int LZ4_compress_HC_extStateHC (void* state, const char* src, char* dst, int src int LZ4_compress_HC(const char* src, char* dst, int srcSize, int maxDstSize, int compressionLevel) { +#if LZ4HC_HEAPMODE==1 + LZ4HC_Data_Structure* statePtr = malloc(sizeof(LZ4HC_Data_Structure)); +#else LZ4HC_Data_Structure state; - return LZ4_compress_HC_extStateHC(&state, src, dst, srcSize, maxDstSize, compressionLevel); + LZ4HC_Data_Structure* const statePtr = &state; +#endif + int cSize = LZ4_compress_HC_extStateHC(statePtr, src, dst, srcSize, maxDstSize, compressionLevel); +#if LZ4HC_HEAPMODE==1 + free(statePtr); +#endif + return cSize; } |