flate

deflate implementation
git clone git://git.suckless.org/flate
Log | Files | Refs | README

commit 91bbf2dbb704b4556c627c7f5a6d4651a1c7a613
parent a134df0ce7efca5185cfaaf05c54e250fbc5bc59
Author: nsz <nszabolcs@gmail.com>
Date:   Tue, 11 Aug 2009 09:53:43 +0200

deflate match modification
Diffstat:
deflate.c | 22+++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/deflate.c b/deflate.c @@ -483,28 +483,27 @@ static void recordlit(State *s, int c) { } /* multiplicative hash */ -static ushort gethash(uchar *p) { +static int gethash(uchar *p) { return (0x9e3779b1 * ((p[0]<<16) + (p[1]<<8) + p[2]) >> (32 - HashBits)) % HashSize; } -static ushort updatechain(State *s) { - ushort i, h; +static int updatechain(State *s) { + int h, i; if (s->avail < MinMatch) return 0; h = gethash(s->win + s->pos); i = s->head[h]; s->head[h] = s->pos; - s->chain[s->pos % MaxDist] = i; if (i >= s->pos || s->pos - i >= MaxDist) - return 0; + i = 0; + s->chain[s->pos % MaxDist] = i; return i; } static Match getmatch(State *s, int mpos) { Match m = {0, MinMatch-1}; int len; - int maxlen = s->avail < MaxMatch ? s->avail : MaxMatch; int limit = s->pos - MaxDist; int chainlen = MaxChainLen; uchar *q; @@ -514,21 +513,22 @@ static Match getmatch(State *s, int mpos) { do { q = s->win + mpos; /* at least m.len+1 long */ - if (q[m.len] != p[m.len] || q[0] != p[0]) + if (q[m.len] != p[m.len] || q[m.len-1] != p[m.len-1] || q[0] != p[0]) continue; - /* loop unroll: MaxMatch % 10 == 8, overflow if avail < MaxMatch */ - /* only little gain over while (++p != end && *++q == *p); */ + /* loop unroll: MaxMatch % 10 == 8, overflow if avail < MaxMatch, only little gain do; while (*++q == *++p && *++q == *++p && *++q == *++p && *++q == *++p && *++q == *++p && *++q == *++p && *++q == *++p && ++p != end && *++q == *p && *++q == *++p && *++q == *++p); + */ + while (++p != end && *++q == *p); len = MaxMatch - (end - p); p -= len; if (len > m.len) { m.dist = s->pos - mpos; - if (len >= maxlen) { - m.len = maxlen; + if (len >= s->avail || len == MaxMatch) { + m.len = s->avail < MaxMatch ? s->avail : MaxMatch; return m; } m.len = len;