summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorW. Felix Handte <w@felixhandte.com>2018-01-26 17:06:43 (GMT)
committerW. Felix Handte <w@felixhandte.com>2018-03-12 18:58:43 (GMT)
commit80790c587b55b8e0b932b64c892ba984cde1b70f (patch)
tree549fa46d329218ef71a2f410adfbb7a5724e9e3e
parent9dcd9abc14a33b6ac6c91dd727235db1daabe066 (diff)
downloadlz4-80790c587b55b8e0b932b64c892ba984cde1b70f.zip
lz4-80790c587b55b8e0b932b64c892ba984cde1b70f.tar.gz
lz4-80790c587b55b8e0b932b64c892ba984cde1b70f.tar.bz2
Copy the Dict Table Into the Context for Large Compressions
-rw-r--r--lib/lz4.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/lib/lz4.c b/lib/lz4.c
index cace35f..f7de564 100644
--- a/lib/lz4.c
+++ b/lib/lz4.c
@@ -1205,20 +1205,25 @@ int LZ4_compress_fast_continue (LZ4_stream_t* LZ4_stream, const char* source, ch
/* external dictionary mode */
{ int result;
- if ((streamPtr->dictSize < 64 KB) && (streamPtr->dictSize < streamPtr->currentOffset)) {
- if (streamPtr->dictCtx) {
- LZ4_resetTable(streamPtr, inputSize, tableType, usingExtDictCtx);
+ if (streamPtr->dictCtx && inputSize < 2 KB) {
+ LZ4_resetTable(streamPtr, inputSize, tableType, usingExtDictCtx);
+ if ((streamPtr->dictCtx->dictSize < 64 KB) && (streamPtr->dictCtx->dictSize < streamPtr->currentOffset)) {
result = LZ4_compress_generic(streamPtr, source, dest, inputSize, maxOutputSize, limitedOutput, tableType, usingExtDictCtx, dictSmall, acceleration);
} else {
- LZ4_resetTable(streamPtr, inputSize, tableType, usingExtDict);
- result = LZ4_compress_generic(streamPtr, source, dest, inputSize, maxOutputSize, limitedOutput, tableType, usingExtDict, dictSmall, acceleration);
+ result = LZ4_compress_generic(streamPtr, source, dest, inputSize, maxOutputSize, limitedOutput, tableType, usingExtDictCtx, noDictIssue, acceleration);
}
} else {
if (streamPtr->dictCtx) {
- LZ4_resetTable(streamPtr, inputSize, tableType, usingExtDictCtx);
- result = LZ4_compress_generic(streamPtr, source, dest, inputSize, maxOutputSize, limitedOutput, tableType, usingExtDictCtx, noDictIssue, acceleration);
+ /* For compressing large blobs, it is faster to pay the setup
+ * cost to copy the dictionary's tables into the active context,
+ * so that the compression loop is only looking in one table.
+ */
+ memcpy(streamPtr, streamPtr->dictCtx, sizeof(LZ4_stream_t));
+ }
+ LZ4_resetTable(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_resetTable(streamPtr, inputSize, tableType, usingExtDict);
result = LZ4_compress_generic(streamPtr, source, dest, inputSize, maxOutputSize, limitedOutput, tableType, usingExtDict, noDictIssue, acceleration);
}
}