diff options
author | yann.collet.73@gmail.com <yann.collet.73@gmail.com@650e7d94-2a16-8b24-b05c-7c0b3f6821cd> | 2012-12-11 01:38:32 (GMT) |
---|---|---|
committer | yann.collet.73@gmail.com <yann.collet.73@gmail.com@650e7d94-2a16-8b24-b05c-7c0b3f6821cd> | 2012-12-11 01:38:32 (GMT) |
commit | 024f83c1e56de5b7784d51d990359ef283a1d48c (patch) | |
tree | 120a24f2238f7d35273519c80da1122a99db0862 | |
parent | ffb27d4eca6bd80c068e745388faa31a0982115c (diff) | |
download | lz4-024f83c1e56de5b7784d51d990359ef283a1d48c.zip lz4-024f83c1e56de5b7784d51d990359ef283a1d48c.tar.gz lz4-024f83c1e56de5b7784d51d990359ef283a1d48c.tar.bz2 |
Improved decoding speed, thanks to several contributions from Ludvig Strigeus (issues 49, 50 & 54)
Removed unnecessary assignment within LZ4_uncompress_unknownSize() (reported by Shivram)
git-svn-id: https://lz4.googlecode.com/svn/trunk@85 650e7d94-2a16-8b24-b05c-7c0b3f6821cd
-rw-r--r-- | lz4.c | 63 |
1 files changed, 33 insertions, 30 deletions
@@ -701,10 +701,13 @@ int LZ4_uncompress(const char* source, BYTE* const oend = op + osize;
BYTE* cpy;
- BYTE token;
+ unsigned token;
- int len, length;
- size_t dec[] ={0, 3, 2, 3, 0, 0, 0, 0};
+ size_t length;
+ size_t dec32table[] = {0, 3, 2, 3, 0, 0, 0, 0};
+#if LZ4_ARCH64
+ size_t dec64table[] = {0, 0, 0, -1, 0, 1, 2, 3};
+#endif
// Main Loop
@@ -712,7 +715,7 @@ int LZ4_uncompress(const char* source, {
// get runlength
token = *ip++;
- if ((length=(token>>ML_BITS)) == RUN_MASK) { for (;(len=*ip++)==255;length+=255){} length += len; }
+ if ((length=(token>>ML_BITS)) == RUN_MASK) { size_t len; for (;(len=*ip++)==255;length+=255){} length += len; }
// copy literals
cpy = op+length;
@@ -727,27 +730,26 @@ int LZ4_uncompress(const char* source, // get offset
LZ4_READ_LITTLEENDIAN_16(ref,cpy,ip); ip+=2;
- if (ref < (BYTE* const)dest) goto _output_error; // Error : offset create reference outside destination buffer
+ if unlikely(ref < (BYTE* const)dest) goto _output_error; // Error : offset create reference outside destination buffer
// get matchlength
if ((length=(token&ML_MASK)) == ML_MASK) { for (;*ip==255;length+=255) {ip++;} length += *ip++; }
// copy repeated sequence
- if unlikely(op-ref<STEPSIZE)
+ if unlikely((op-ref)<STEPSIZE)
{
#if LZ4_ARCH64
- size_t dec2table[]={0, 0, 0, -1, 0, 1, 2, 3};
- size_t dec2 = dec2table[op-ref];
+ size_t dec64 = dec64table[op-ref];
#else
- const int dec2 = 0;
+ const int dec64 = 0;
#endif
- *op++ = *ref++;
- *op++ = *ref++;
- *op++ = *ref++;
- *op++ = *ref++;
- ref -= dec[op-ref];
- A32(op)=A32(ref); op += STEPSIZE-4;
- ref -= dec2;
+ op[0] = ref[0];
+ op[1] = ref[1];
+ op[2] = ref[2];
+ op[3] = ref[3];
+ op += 4, ref += 4; ref -= dec32table[op-ref];
+ A32(op) = A32(ref);
+ op += STEPSIZE-4; ref -= dec64;
} else { LZ4_COPYSTEP(ref,op); }
cpy = op + length - (STEPSIZE-4);
if (cpy>oend-COPYLENGTH)
@@ -787,14 +789,17 @@ int LZ4_uncompress_unknownOutputSize( BYTE* const oend = op + maxOutputSize;
BYTE* cpy;
- size_t dec[] ={0, 3, 2, 3, 0, 0, 0, 0};
+ size_t dec32table[] = {0, 3, 2, 3, 0, 0, 0, 0};
+#if LZ4_ARCH64
+ size_t dec64table[] = {0, 0, 0, -1, 0, 1, 2, 3};
+#endif
// Main Loop
while (ip<iend)
{
- BYTE token;
- int length;
+ unsigned token;
+ size_t length;
// get runlength
token = *ip++;
@@ -808,7 +813,6 @@ int LZ4_uncompress_unknownOutputSize( if (ip+length != iend) goto _output_error; // Error : LZ4 format requires to consume all input at this stage
memcpy(op, ip, length);
op += length;
- ip = iend;
break; // Necessarily EOF, due to parsing restrictions
}
LZ4_WILDCOPY(ip, op, cpy); ip -= (op-cpy); op = cpy;
@@ -824,18 +828,17 @@ int LZ4_uncompress_unknownOutputSize( if unlikely(op-ref<STEPSIZE)
{
#if LZ4_ARCH64
- size_t dec2table[]={0, 0, 0, -1, 0, 1, 2, 3};
- size_t dec2 = dec2table[op-ref];
+ size_t dec64 = dec64table[op-ref];
#else
- const int dec2 = 0;
+ const int dec64 = 0;
#endif
- *op++ = *ref++;
- *op++ = *ref++;
- *op++ = *ref++;
- *op++ = *ref++;
- ref -= dec[op-ref];
- A32(op)=A32(ref); op += STEPSIZE-4;
- ref -= dec2;
+ op[0] = ref[0];
+ op[1] = ref[1];
+ op[2] = ref[2];
+ op[3] = ref[3];
+ op += 4, ref += 4; ref -= dec32table[op-ref];
+ A32(op) = A32(ref);
+ op += STEPSIZE-4; ref -= dec64;
} else { LZ4_COPYSTEP(ref,op); }
cpy = op + length - (STEPSIZE-4);
if (cpy>oend-COPYLENGTH)
|