Add LZ4_compress_fast_safeExtState Function

This commit is contained in:
W. Felix Handte 2018-02-02 11:41:11 -05:00
parent f34fb3c42d
commit d6a3024dbb
2 changed files with 17 additions and 1 deletions

View File

@ -738,10 +738,18 @@ _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)

View File

@ -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);