32#if !defined(FASTLZ__COMPRESSOR) && !defined(FASTLZ_DECOMPRESSOR)
40#if defined(WIN32) || defined(__NT__) || defined(_WIN32) || defined(__WIN32__)
41#if defined(_MSC_VER) || defined(__GNUC__)
43#pragma warning(disable : 4242)
44#pragma warning(disable : 4244)
51#if defined(__GNUC__) && (__GNUC__ > 2)
52#define FASTLZ_EXPECT_CONDITIONAL(c) (__builtin_expect((c), 1))
53#define FASTLZ_UNEXPECT_CONDITIONAL(c) (__builtin_expect((c), 0))
55#define FASTLZ_EXPECT_CONDITIONAL(c) (c)
56#define FASTLZ_UNEXPECT_CONDITIONAL(c) (c)
62#if defined(__GNUC__) || defined(__DMC__) || defined(__POCC__) ||\
63 defined(__WATCOMC__) || defined(__SUNPRO_C)
64#define FASTLZ_INLINE inline
65#elif defined(__BORLANDC__) || defined(_MSC_VER) || defined(__LCC__)
66#define FASTLZ_INLINE __inline
74#if !defined(FASTLZ_STRICT_ALIGN)
75#define FASTLZ_STRICT_ALIGN
76#if defined(__i386__) || defined(__386)
77#undef FASTLZ_STRICT_ALIGN
78#elif defined(__i486__) || defined(__i586__) || defined(__i686__)
79#undef FASTLZ_STRICT_ALIGN
81#undef FASTLZ_STRICT_ALIGN
83#undef FASTLZ_STRICT_ALIGN
85#undef FASTLZ_STRICT_ALIGN
87#undef FASTLZ_STRICT_ALIGN
97#define MAX_DISTANCE 8192
99#if !defined(FASTLZ_STRICT_ALIGN)
100#define FASTLZ_READU16(p) (*((const unsigned short *)(p)))
102#define FASTLZ_READU16(p) ((p)[0] | (p)[1]<<8)
106#define HASH_SIZE (1 << HASH_LOG)
107#define HASH_MASK (HASH_SIZE - 1)
108#define HASH_FUNCTION(v, p) {\
109 v = FASTLZ_READU16(p);\
110 v ^= FASTLZ_READU16(p + 1)^\
111 (v>>(16 - HASH_LOG));\
116#define FASTLZ_LEVEL 1
118#undef FASTLZ_COMPRESSOR
119#undef FASTLZ_DECOMPRESSOR
120#define FASTLZ_COMPRESSOR fastlz1_compress
121#define FASTLZ_DECOMPRESSOR fastlz1_decompress
125 void *output,
int maxout);
129#define FASTLZ_LEVEL 2
132#define MAX_DISTANCE 8191
133#define MAX_FARDISTANCE (65535 + MAX_DISTANCE - 1)
135#undef FASTLZ_COMPRESSOR
136#undef FASTLZ_DECOMPRESSOR
137#define FASTLZ_COMPRESSOR fastlz2_compress
138#define FASTLZ_DECOMPRESSOR fastlz2_decompress
142 void *output,
int maxout);
149 return fastlz1_compress(input, length, output);
152 return fastlz2_compress(input, length, output);
158 int level = ((*(
const unsigned char *)input) >> 5) + 1;
161 return fastlz1_decompress(input, length, output, maxout);
163 return fastlz2_decompress(input, length, output, maxout);
173 return fastlz1_compress(input, length, output);
175 return fastlz2_compress(input, length, output);
186 const unsigned char *ip = (
const unsigned char *) input;
187 const unsigned char *ip_bound = ip + length - 2;
188 const unsigned char *ip_limit = ip + length - 12;
189 unsigned char *op = (
unsigned char *) output;
190 static const unsigned char *g_htab[
HASH_SIZE];
192 const unsigned char **htab = g_htab;
193 const unsigned char **hslot;
204 while (ip <= ip_bound)
212 for (hslot = htab; hslot < htab +
HASH_SIZE; hslot++)
223 const unsigned char *ref;
224 unsigned int distance;
227 unsigned int len = 3;
230 const unsigned char *anchor = ip;
234 if (ip[0] == ip[-1] &&
238 ref = anchor - 1 + 3;
249 distance = anchor - ref;
263 *ref++ != *ip++ || *ref++ != *ip++ ||
270 if (*ip++ != *ref++ || *ip++ != *ref++)
286 unsigned char x = ip[-1];
287 while (ip < ip_bound)
312 while (ip < ip_bound)
321 *(op - copy - 1) = copy - 1;
337 *op++ = (len << 5) + (distance >> 8);
338 *op++ = (distance & 255);
340 *op++ = (7 << 5) + (distance >> 8);
341 for (len -= 7; len >= 255; len -= 255)
344 *op++ = (distance & 255);
350 *op++ = (len << 5) + 31;
352 *op++ = distance >> 8;
353 *op++ = distance & 255;
356 *op++ = (7 << 5) + 31;
357 for (len -= 7; len >= 255; len -= 255)
361 *op++ = distance >> 8;
362 *op++ = distance & 255;
369 *op++ = (7 << 5) + (distance >> 8);
371 *op++ = (distance & 255);
376 *op++ = (len << 5) + (distance >> 8);
377 *op++ = (distance & 255);
379 *op++ = (7 << 5) + (distance >> 8);
381 *op++ = (distance & 255);
408 while (ip <= ip_bound) {
419 *(op - copy - 1) = copy - 1;
425 *(
unsigned char *)output |= (1 << 5);
428 return op - (
unsigned char *)output;
432 void *output,
int maxout)
434 const unsigned char *ip = (
const unsigned char *) input;
435 const unsigned char *ip_limit = ip + length;
436 unsigned char *op = (
unsigned char *) output;
437 unsigned char *op_limit = op + maxout;
438 unsigned int ctrl = (*ip++) & 31;
442 const unsigned char *ref = op;
443 unsigned int len = ctrl >> 5;
444 unsigned int ofs = (ctrl & 31) << 8;
460 }
while (code == 255);
480 (
unsigned char *)output)
492 unsigned char b = ref[-1];
499#if !defined(FASTLZ_STRICT_ALIGN)
500 const unsigned short *p;
509#if !defined(FASTLZ_STRICT_ALIGN)
517 q = (
unsigned short *) op;
519 p = (
const unsigned short *) ref;
520 for (len >>= 1; len > 4; len -= 4) {
543 for (--ctrl; ctrl; ctrl--)
552 return op - (
unsigned char *)output;
#define FASTLZ_EXPECT_CONDITIONAL(c)
int fastlz_decompress(const void *input, int length, void *output, int maxout)
#define FASTLZ_UNEXPECT_CONDITIONAL(c)
#define FASTLZ_DECOMPRESSOR
int fastlz_compress(const void *input, int length, void *output)
#define FASTLZ_COMPRESSOR
#define HASH_FUNCTION(v, p)
#define FASTLZ_READU16(p)
int fastlz_compress_level(int level, const void *input, int length, void *output)