diff options
author | yann.collet.73@gmail.com <yann.collet.73@gmail.com@650e7d94-2a16-8b24-b05c-7c0b3f6821cd> | 2011-09-20 10:01:23 (GMT) |
---|---|---|
committer | yann.collet.73@gmail.com <yann.collet.73@gmail.com@650e7d94-2a16-8b24-b05c-7c0b3f6821cd> | 2011-09-20 10:01:23 (GMT) |
commit | d9bf974023d85f68b32b8c36052f4926f0478182 (patch) | |
tree | 26a370e32ccaf45609480b6f3dad36ea20c11edd /lz4.c | |
parent | babbc0f494b89b7ce2a7673bd0c3a3cf13fd9ea3 (diff) | |
download | lz4-d9bf974023d85f68b32b8c36052f4926f0478182.zip lz4-d9bf974023d85f68b32b8c36052f4926f0478182.tar.gz lz4-d9bf974023d85f68b32b8c36052f4926f0478182.tar.bz2 |
Small compression speed improvement
git-svn-id: https://lz4.googlecode.com/svn/trunk@24 650e7d94-2a16-8b24-b05c-7c0b3f6821cd
Diffstat (limited to 'lz4.c')
-rw-r--r-- | lz4.c | 43 |
1 files changed, 27 insertions, 16 deletions
@@ -67,6 +67,7 @@ //**************************************
#define MINMATCH 4
#define SKIPSTRENGTH 6
+#define HEAPLIMIT 13
#define MAXD_LOG 16
#define MAX_DISTANCE ((1 << MAXD_LOG) - 1)
@@ -106,8 +107,12 @@ int LZ4_compressCtx(void** ctx, char* dest,
int isize)
{
+#if HASH_LOG>HEAPLIMIT
struct refTables *srt = (struct refTables *) (*ctx);
const BYTE** HashTable;
+#else
+ const BYTE* HashTable[HASHTABLESIZE] = {0};
+#endif
const BYTE* ip = (BYTE*) source;
const BYTE* anchor = ip;
@@ -124,6 +129,7 @@ int LZ4_compressCtx(void** ctx, // Init
+#if HASH_LOG>HEAPLIMIT
if (*ctx == NULL)
{
srt = (struct refTables *) malloc ( sizeof(struct refTables) );
@@ -131,6 +137,7 @@ int LZ4_compressCtx(void** ctx, }
HashTable = srt->hashTable;
memset((void*)HashTable, 0, sizeof(srt->hashTable));
+#endif
// First Byte
@@ -138,26 +145,26 @@ int LZ4_compressCtx(void** ctx, ip++; forwardH = HASH_VALUE(ip);
// Main Loop
- for ( ; ; ) - { - int segmentSize = (1U << skipStrength) + 3; - const BYTE* forwardIp = ip; - const BYTE* ref; - + for ( ; ; )
+ {
+ int segmentSize = (1U << skipStrength) + 3;
+ const BYTE* forwardIp = ip;
+ const BYTE* ref;
+
// Find a match
- do { - U32 h = forwardH; - int skipped = segmentSize++ >> skipStrength; - ip = forwardIp; - forwardIp = ip + skipped; - - if (forwardIp > ilimit) { goto _last_literals; } + do {
+ 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)); +
+ } while ((ref < ip - MAX_DISTANCE) || (*(U32*)ref != *(U32*)ip));
// Catch up
while ((ip>anchor) && (ref>(BYTE*)source) && (ip[-1]==ref[-1])) { ip--; ref--; }
@@ -230,15 +237,19 @@ int LZ4_compress(char* source, char* dest,
int isize)
{
+#if HASH_LOG>HEAPLIMIT
void* ctx = malloc(sizeof(struct refTables));
int result = LZ4_compressCtx(&ctx, source, dest, isize);
free(ctx);
-
return result;
+#else
+ return LZ4_compressCtx(NULL, source, dest, isize);
+#endif
}
+
//****************************
// Decompression CODE
//****************************
|