}
-LZ4_FORCE_INLINE void LZ4_resetTable(
+LZ4_FORCE_INLINE void LZ4_prepareTable(
LZ4_stream_t_internal* const cctx,
const int inputSize,
const tableType_t tableType,
cctx->currentOffset = 0;
cctx->tableType = unusedTable;
}
+ /* If the current offset is zero, we will never look in the external
+ * dictionary context, since there is no value a table entry can take that
+ * indicates a miss. In that case, we need to bump the offset to something
+ * non-zero.
+ */
if (dictDirective == usingExtDictCtx &&
tableType != byPtr &&
cctx->currentOffset == 0)
}
}
-
-int LZ4_compress_fast_safeExtState(void* state, const char* source, char* dest, int inputSize, int maxOutputSize, int acceleration)
+/**
+ * LZ4_compress_fast_extState_noReset is a variant of LZ4_compress_fast_extState
+ * that can be used when the state is known to have already been initialized
+ * (via LZ4_resetStream or an earlier call to LZ4_compress_fast_extState /
+ * LZ4_compress_fast_extState_noReset). This can provide significantly better
+ * performance when the context reset would otherwise be a significant part of
+ * the cost of the compression, e.g., when the data to be compressed is small.
+ */
+int LZ4_compress_fast_extState_noReset(void* state, const char* source, char* dest, int inputSize, int maxOutputSize, int acceleration)
{
LZ4_stream_t_internal* ctx = &((LZ4_stream_t*)state)->internal_donotuse;
if (acceleration < 1) acceleration = ACCELERATION_DEFAULT;
if (maxOutputSize >= LZ4_compressBound(inputSize)) {
if (inputSize < LZ4_64Klimit) {
const tableType_t tableType = byU16;
- LZ4_resetTable(ctx, inputSize, tableType, noDict);
+ LZ4_prepareTable(ctx, inputSize, tableType, noDict);
if (ctx->currentOffset) {
return LZ4_compress_generic(ctx, source, dest, inputSize, 0, notLimited, tableType, noDict, dictSmall, acceleration);
} else {
}
} else {
const tableType_t tableType = (sizeof(void*)==8) ? byU32 : byPtr;
- LZ4_resetTable(ctx, inputSize, tableType, noDict);
+ LZ4_prepareTable(ctx, inputSize, tableType, noDict);
if (ctx->currentOffset) {
ctx->currentOffset += 64 KB;
}
} else {
if (inputSize < LZ4_64Klimit) {
const tableType_t tableType = byU16;
- LZ4_resetTable(ctx, inputSize, tableType, noDict);
+ LZ4_prepareTable(ctx, inputSize, tableType, noDict);
if (ctx->currentOffset) {
return LZ4_compress_generic(ctx, source, dest, inputSize, maxOutputSize, limitedOutput, tableType, noDict, dictSmall, acceleration);
} else {
}
} else {
const tableType_t tableType = (sizeof(void*)==8) ? byU32 : byPtr;
- LZ4_resetTable(ctx, inputSize, tableType, noDict);
+ LZ4_prepareTable(ctx, inputSize, tableType, noDict);
if (ctx->currentOffset) {
ctx->currentOffset += 64 KB;
}
/* prefix mode : source data follows dictionary */
if (dictEnd == (const BYTE*)source) {
- LZ4_resetTable(streamPtr, inputSize, tableType, withPrefix64k);
+ LZ4_prepareTable(streamPtr, inputSize, tableType, withPrefix64k);
if ((streamPtr->dictSize < 64 KB) && (streamPtr->dictSize < streamPtr->currentOffset))
return LZ4_compress_generic(streamPtr, source, dest, inputSize, maxOutputSize, limitedOutput, tableType, withPrefix64k, dictSmall, acceleration);
else
memcpy(streamPtr, streamPtr->dictCtx, sizeof(LZ4_stream_t));
result = LZ4_compress_generic(streamPtr, source, dest, inputSize, maxOutputSize, limitedOutput, tableType, usingExtDict, noDictIssue, acceleration);
} else {
- LZ4_resetTable(streamPtr, inputSize, tableType, usingExtDictCtx);
+ LZ4_prepareTable(streamPtr, inputSize, tableType, usingExtDictCtx);
result = LZ4_compress_generic(streamPtr, source, dest, inputSize, maxOutputSize, limitedOutput, tableType, usingExtDictCtx, noDictIssue, acceleration);
}
} else {
- LZ4_resetTable(streamPtr, inputSize, tableType, usingExtDict);
+ LZ4_prepareTable(streamPtr, inputSize, tableType, usingExtDict);
if ((streamPtr->dictSize < 64 KB) && (streamPtr->dictSize < streamPtr->currentOffset)) {
result = LZ4_compress_generic(streamPtr, source, dest, inputSize, maxOutputSize, limitedOutput, tableType, usingExtDict, dictSmall, acceleration);
} else {
/*!
-LZ4_compress_fast_safeExtState() :
+LZ4_compress_fast_extState_noReset() :
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.
+ Use the _noReset variant if LZ4_resetStream() was called on the state
+ buffer before being used for the first time (calls to both extState
+ functions leave the state in a safe state, so zeroing is not required
+ between calls). Otherwise, using the 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_noReset (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);