summaryrefslogtreecommitdiffstats
path: root/lz4.c
diff options
context:
space:
mode:
authorYann Collet <yann.collet.73@gmail.com>2014-05-23 20:01:55 (GMT)
committerYann Collet <yann.collet.73@gmail.com>2014-05-23 20:01:55 (GMT)
commit971f61212292bab48ed5e9e5c7f69ece34380fcc (patch)
tree68441997f4f08e9e899e5d8bbd12542f28909156 /lz4.c
parent4b43c2bd980a1582dc9dbf7fe7f0701c12cf5000 (diff)
downloadlz4-971f61212292bab48ed5e9e5c7f69ece34380fcc.zip
lz4-971f61212292bab48ed5e9e5c7f69ece34380fcc.tar.gz
lz4-971f61212292bab48ed5e9e5c7f69ece34380fcc.tar.bz2
speed optimization
Diffstat (limited to 'lz4.c')
-rwxr-xr-xlz4.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/lz4.c b/lz4.c
index 00c2a64..0d7f871 100755
--- a/lz4.c
+++ b/lz4.c
@@ -666,9 +666,17 @@ static inline int LZ4_compress_2_generic (LZ4_dict_t* LZ4_dict,
const U32 dictSize = streamPtr->dictSize;
const BYTE* const dictionary = streamPtr->dictionary;
- streamPtr->dictionary = (const BYTE*)source;
- streamPtr->dictSize = (U32)inputSize;
- streamPtr->currentOffset += (U32)inputSize;
+ if (dict == usingDict)
+ {
+ streamPtr->dictionary = (const BYTE*)source;
+ streamPtr->dictSize = (U32)inputSize;
+ streamPtr->currentOffset += (U32)inputSize;
+ }
+ else
+ {
+ streamPtr->dictSize += (U32)inputSize;
+ streamPtr->currentOffset += (U32)inputSize;
+ }
{
U32 ipIndex = currentOffset;
@@ -697,19 +705,21 @@ static inline int LZ4_compress_2_generic (LZ4_dict_t* LZ4_dict,
/* Main Loop */
for ( ; ; )
{
- int searchMatchNb = (1U << skipStrength) - 1;
+ int searchMatchNb = (1U << skipStrength);
const BYTE* ref;
const BYTE* lowLimit;
BYTE* token;
U32 refIndex;
- ipIndex = (U32)(ip - base);
+ U32 forwardH = LZ4_hashPosition(ip, tableType);
+ U32 forwardIpIndex = (U32)(ip - base);
/* Find a match */
do {
- U32 h;
+ U32 h = forwardH;
+ ipIndex = forwardIpIndex;
+ forwardIpIndex += searchMatchNb++ >> skipStrength;
+ forwardH = LZ4_hashPosition(base + forwardIpIndex, tableType);
- ipIndex += searchMatchNb++ >> skipStrength;
- h = LZ4_hashPosition(base + ipIndex, tableType);
refIndex = streamPtr->hashTable[h];
streamPtr->hashTable[h] = ipIndex;
@@ -767,7 +777,8 @@ static inline int LZ4_compress_2_generic (LZ4_dict_t* LZ4_dict,
}
else
{
- matchLength = LZ4_count(ip+MINMATCH, ref+MINMATCH, matchlimit);
+ matchLength = base + ipIndex - ip;
+ matchLength += LZ4_count(base+ipIndex+MINMATCH, base+refIndex+MINMATCH, matchlimit);
}
ip += matchLength + MINMATCH;
if (matchLength>=ML_MASK)
@@ -834,7 +845,7 @@ int LZ4_compress_limitedOutput_usingDict (LZ4_dict_t* LZ4_dict, const char* sour
return LZ4_compress_usingDict_generic(LZ4_dict, source, dest, inputSize, maxOutputSize, limitedOutput);
}
-// Debug function only, to measure performance differences
+// Hidden debug function, to force separate dictionary mode
int LZ4_compress_forceDict (LZ4_dict_t* LZ4_dict, const char* source, char* dest, int inputSize)
{
return LZ4_compress_2_generic(LZ4_dict, source, dest, inputSize, 0, notLimited, usingDict);