diff options
author | W. Felix Handte <w@felixhandte.com> | 2018-02-02 16:41:11 (GMT) |
---|---|---|
committer | W. Felix Handte <w@felixhandte.com> | 2018-03-12 18:58:43 (GMT) |
commit | d6a3024dbb6375190e6e02ad8b06aae28e76b946 (patch) | |
tree | c99d17241fffde37f1765b87b3b0053c79f4b5bf | |
parent | f34fb3c42dbb824af97800eefdb487dff31e0c13 (diff) | |
download | lz4-d6a3024dbb6375190e6e02ad8b06aae28e76b946.zip lz4-d6a3024dbb6375190e6e02ad8b06aae28e76b946.tar.gz lz4-d6a3024dbb6375190e6e02ad8b06aae28e76b946.tar.bz2 |
Add LZ4_compress_fast_safeExtState Function
-rw-r--r-- | lib/lz4.c | 10 | ||||
-rw-r--r-- | lib/lz4.h | 8 |
2 files changed, 17 insertions, 1 deletions
@@ -739,9 +739,17 @@ _clean_up: int LZ4_compress_fast_extState(void* state, const char* source, char* dest, int inputSize, int maxOutputSize, int acceleration) { + LZ4_resetStream((LZ4_stream_t*)state); + return LZ4_compress_fast_safeExtState(state, source, dest, inputSize, maxOutputSize, acceleration); +} + + +int LZ4_compress_fast_safeExtState(void* state, const char* source, char* dest, int inputSize, int maxOutputSize, int acceleration) +{ LZ4_stream_t_internal* ctx = &((LZ4_stream_t*)state)->internal_donotuse; - LZ4_resetStream((LZ4_stream_t*)state); if (acceleration < 1) acceleration = ACCELERATION_DEFAULT; + ctx->dictionary = NULL; + ctx->dictSize = 0; if (maxOutputSize >= LZ4_compressBound(inputSize)) { if (inputSize < LZ4_64Klimit) @@ -179,13 +179,21 @@ LZ4LIB_API int LZ4_compress_fast (const char* src, char* dst, int srcSize, int d /*! +LZ4_compress_fast_safeExtState() : LZ4_compress_fast_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, and allocate it on 8-bytes boundaries (using malloc() typically). Then, provide it as 'void* state' to compression function. + + Use _safeExtState variant if LZ4_resetStream() was called on the state + buffer before being used for the first time (calls to this function leave + the state in a safe state, so zeroing is not required between calls). + Otherwise, using legacy _extState requires LZ4 to reinitialize the state + internally for every call. */ LZ4LIB_API int LZ4_sizeofState(void); +LZ4LIB_API int LZ4_compress_fast_safeExtState (void* state, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration); LZ4LIB_API int LZ4_compress_fast_extState (void* state, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration); |