summaryrefslogtreecommitdiff
path: root/lzf_c.c
diff options
context:
space:
mode:
Diffstat (limited to 'lzf_c.c')
-rw-r--r--lzf_c.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/lzf_c.c b/lzf_c.c
index eeb114e..43f8fb5 100644
--- a/lzf_c.c
+++ b/lzf_c.c
@@ -46,8 +46,8 @@
* the hashing function might seem strange, just believe me
* it works ;)
*/
-#define FRST(p) (((p[0]) << 8) + p[1])
-#define NEXT(v,p) (((v) << 8) + p[2])
+#define FRST(p) (((p[0]) << 8) | p[1])
+#define NEXT(v,p) (((v) << 8) | p[2])
#define IDX(h) ((((h ^ (h << 5)) >> (3*8 - HLOG)) - h*5) & (HSIZE - 1))
/*
* IDX works because it is very similar to a multiplicative hash, e.g.
@@ -139,13 +139,13 @@ lzf_compress (const void *const in_data, unsigned int in_len,
unsigned int maxlen = in_end - ip - len;
maxlen = maxlen > MAX_REF ? MAX_REF : maxlen;
+ if (op + lit + 1 + 3 >= out_end)
+ return 0;
+
do
len++;
while (len < maxlen && ref[len] == ip[len]);
- if (op + lit + 1 + 3 >= out_end)
- return 0;
-
if (lit)
{
*op++ = lit - 1;
@@ -170,12 +170,22 @@ lzf_compress (const void *const in_data, unsigned int in_len,
*op++ = off;
-#if ULTRA_FAST
+#if ULTRA_FAST || VERY_FAST
ip += len;
+#if VERY_FAST && !ULTRA_FAST
+ --ip;
+#endif
hval = FRST (ip);
+
+ hval = NEXT (hval, ip);
+ htab[IDX (hval)] = ip;
+ ip++;
+
+#if VERY_FAST && !ULTRA_FAST
hval = NEXT (hval, ip);
htab[IDX (hval)] = ip;
ip++;
+#endif
#else
do
{