small compression speed improvement
git-svn-id: https://lz4.googlecode.com/svn/trunk@22 650e7d94-2a16-8b24-b05c-7c0b3f6821cd
This commit is contained in:
parent
e154e125fc
commit
e8d1e99112
45
lz4.c
45
lz4.c
@ -111,7 +111,6 @@ int LZ4_compressCtx(void** ctx,
|
|||||||
|
|
||||||
const BYTE* ip = (BYTE*) source;
|
const BYTE* ip = (BYTE*) source;
|
||||||
const BYTE* anchor = ip;
|
const BYTE* anchor = ip;
|
||||||
const BYTE* ref;
|
|
||||||
const BYTE* const iend = ip + isize;
|
const BYTE* const iend = ip + isize;
|
||||||
const BYTE* const ilimit = iend - MINMATCH;
|
const BYTE* const ilimit = iend - MINMATCH;
|
||||||
|
|
||||||
@ -121,7 +120,7 @@ int LZ4_compressCtx(void** ctx,
|
|||||||
|
|
||||||
int len, length;
|
int len, length;
|
||||||
const int skipStrength = SKIPSTRENGTH;
|
const int skipStrength = SKIPSTRENGTH;
|
||||||
U32 skipped = 1U << skipStrength;
|
U32 forwardH;
|
||||||
|
|
||||||
|
|
||||||
// Init
|
// Init
|
||||||
@ -131,17 +130,34 @@ int LZ4_compressCtx(void** ctx,
|
|||||||
*ctx = (void*) srt;
|
*ctx = (void*) srt;
|
||||||
}
|
}
|
||||||
HashTable = srt->hashTable;
|
HashTable = srt->hashTable;
|
||||||
memset(HashTable, 0, sizeof(srt->hashTable));
|
memset((void*)HashTable, 0, sizeof(srt->hashTable));
|
||||||
|
|
||||||
|
|
||||||
|
// First Byte
|
||||||
|
HashTable[HASH_VALUE(ip)] = ip++;
|
||||||
|
forwardH = HASH_VALUE(ip);
|
||||||
|
|
||||||
// Main Loop
|
// Main Loop
|
||||||
while (ip < ilimit+1)
|
for ( ; ; )
|
||||||
{
|
{
|
||||||
ref = HashTable[HASH_VALUE(ip)];
|
int segmentSize = (1U << skipStrength) + 3;
|
||||||
HashTable[HASH_VALUE(ip)] = ip;
|
const BYTE* forwardIp = ip;
|
||||||
|
const BYTE* ref;
|
||||||
|
|
||||||
// Min Match
|
// Find a match
|
||||||
if ((ref < ip - MAX_DISTANCE) || (*(U32*)ref != *(U32*)ip)) { ip += (skipped++) >> skipStrength ; continue; }
|
do {
|
||||||
skipped = (1U << skipStrength) + 3;
|
U32 h = forwardH;
|
||||||
|
int skipped = segmentSize++ >> skipStrength;
|
||||||
|
ip = forwardIp;
|
||||||
|
forwardIp = ip + skipped;
|
||||||
|
|
||||||
|
if (forwardIp > ilimit) { goto _last_literals; }
|
||||||
|
|
||||||
|
forwardH = HASH_VALUE(forwardIp);
|
||||||
|
ref = HashTable[h];
|
||||||
|
HashTable[h] = ip;
|
||||||
|
|
||||||
|
} while ((ref < ip - MAX_DISTANCE) || (*(U32*)ref != *(U32*)ip));
|
||||||
|
|
||||||
// Catch up
|
// Catch up
|
||||||
while ((ip>anchor) && (ref>(BYTE*)source) && (ip[-1]==ref[-1])) { ip--; ref--; }
|
while ((ip>anchor) && (ref>(BYTE*)source) && (ip[-1]==ref[-1])) { ip--; ref--; }
|
||||||
@ -190,15 +206,16 @@ _endCount:
|
|||||||
|
|
||||||
// Prepare next loop
|
// Prepare next loop
|
||||||
anchor = ip++;
|
anchor = ip++;
|
||||||
|
forwardH = HASH_VALUE(ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_last_literals:
|
||||||
// Encode Last Literals
|
// Encode Last Literals
|
||||||
len = iend - anchor;
|
if (anchor < iend)
|
||||||
if (len)
|
|
||||||
{
|
{
|
||||||
orun=op++;
|
int lastLitRun = iend - anchor;
|
||||||
if (len>=(int)RUN_MASK) { *orun=(RUN_MASK<<ML_BITS); len-=RUN_MASK; for(; len > 254 ; len-=255) *op++ = 255; *op++ = (BYTE) len; }
|
if (lastLitRun>=(int)RUN_MASK) { *op++=(RUN_MASK<<ML_BITS); lastLitRun-=RUN_MASK; for(; lastLitRun > 254 ; lastLitRun-=255) *op++ = 255; *op++ = (BYTE) lastLitRun; }
|
||||||
else *orun = (len<<ML_BITS);
|
else *op++ = (lastLitRun<<ML_BITS);
|
||||||
while (anchor < iend - 3) { *(U32*)op = *(U32*)anchor; op+=4; anchor+=4; }
|
while (anchor < iend - 3) { *(U32*)op = *(U32*)anchor; op+=4; anchor+=4; }
|
||||||
while (anchor < iend ) *op++ = *anchor++;
|
while (anchor < iend ) *op++ = *anchor++;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user