summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorW. Felix Handte <w@felixhandte.com>2018-03-12 22:13:24 (GMT)
committerW. Felix Handte <w@felixhandte.com>2018-03-12 22:34:41 (GMT)
commitf9fef255a12470b7beeaa8635b65fc837d835c84 (patch)
treec710a1b534414e24276e2c9f3c97ba56ac85014b /lib
parent1df5d911aa23e645b873164382a40186ed704bac (diff)
downloadlz4-f9fef255a12470b7beeaa8635b65fc837d835c84.zip
lz4-f9fef255a12470b7beeaa8635b65fc837d835c84.tar.gz
lz4-f9fef255a12470b7beeaa8635b65fc837d835c84.tar.bz2
Renames and Comment Fixes
Diffstat (limited to 'lib')
-rw-r--r--lib/lz4.c32
-rw-r--r--lib/lz4.h14
-rw-r--r--lib/lz4frame.c2
3 files changed, 30 insertions, 18 deletions
diff --git a/lib/lz4.c b/lib/lz4.c
index 1ea8ba1..94248be 100644
--- a/lib/lz4.c
+++ b/lib/lz4.c
@@ -524,7 +524,7 @@ LZ4_FORCE_INLINE const BYTE* LZ4_getPosition(const BYTE* p, const void* tableBas
}
-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,
@@ -547,6 +547,11 @@ LZ4_FORCE_INLINE void LZ4_resetTable(
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)
@@ -825,8 +830,15 @@ int LZ4_compress_fast_extState(void* state, const char* source, char* dest, int
}
}
-
-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;
@@ -837,7 +849,7 @@ int LZ4_compress_fast_safeExtState(void* state, const char* source, char* dest,
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 {
@@ -845,7 +857,7 @@ int LZ4_compress_fast_safeExtState(void* state, const char* source, char* dest,
}
} 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;
}
@@ -854,7 +866,7 @@ int LZ4_compress_fast_safeExtState(void* state, const char* source, char* dest,
} 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 {
@@ -862,7 +874,7 @@ int LZ4_compress_fast_safeExtState(void* state, const char* source, char* dest,
}
} 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;
}
@@ -1213,7 +1225,7 @@ int LZ4_compress_fast_continue (LZ4_stream_t* LZ4_stream, const char* source, ch
/* 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
@@ -1237,11 +1249,11 @@ int LZ4_compress_fast_continue (LZ4_stream_t* LZ4_stream, const char* source, ch
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 {
diff --git a/lib/lz4.h b/lib/lz4.h
index 58a1e39..ca9d552 100644
--- a/lib/lz4.h
+++ b/lib/lz4.h
@@ -179,21 +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_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);
diff --git a/lib/lz4frame.c b/lib/lz4frame.c
index 4cc2ef3..7acd7cf 100644
--- a/lib/lz4frame.c
+++ b/lib/lz4frame.c
@@ -722,7 +722,7 @@ static int LZ4F_compressBlock(void* ctx, const char* src, char* dst, int srcSize
if (cdict) {
return LZ4_compress_fast_continue((LZ4_stream_t*)ctx, src, dst, srcSize, dstCapacity, acceleration);
} else {
- return LZ4_compress_fast_safeExtState(ctx, src, dst, srcSize, dstCapacity, acceleration);
+ return LZ4_compress_fast_extState_noReset(ctx, src, dst, srcSize, dstCapacity, acceleration);
}
}