flate

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

commit 91f4e002ef67509b758a6765a35bba94b13688cd
parent 2a4423264be4b26a110c77a07ccd7e108e90c22d
Author: nsz <nszabolcs@gmail.com>
Date:   Thu, 16 Jul 2009 08:03:05 +0200

better lazy match, dont allow short match with large dist
Diffstat:
deflate_simple.c | 42+++++++++++++-----------------------------
1 file changed, 13 insertions(+), 29 deletions(-)

diff --git a/deflate_simple.c b/deflate_simple.c @@ -19,7 +19,6 @@ enum { MaxChainStep = 64, HashSize = 2039, WinSize = 1 << 15, - SymSize = 1 << 16, LzRunlen = 1<<30 }; @@ -347,7 +346,7 @@ static void deflate_block(State *s, int blocklen) { for (nclen = Nclen; nclen > 4 && clen[clenorder[nclen-1]] == 0; nclen--); /* calc size */ - uncsize = 3 + 4 + 8*blocklen + (16 - 3 - s->nbits)%8; /* byte aligned */ + uncsize = 3 + 16 + 8*blocklen + (16-3-s->nbits) % 8; /* byte aligned */ fixsize = 3; dynsize = 3 + 5 + 5 + 4; dynsize += 3 * nclen; @@ -492,6 +491,8 @@ static Match getmatch(State *s, uchar *src, int len) { } pos = s->chain[pos]; } + if (m.len < MinMatch || (m.len == MinMatch && m.dist > 1<<13)) + m.len = 0; return m; } @@ -546,37 +547,20 @@ int deflate(uchar *src, int len, uchar *dst) { s.src = src; while (len > 0) { m = getmatch(&s, src, len); -/* - if (m.len >= MinMatch) { - recordmatch(&s, m); - step = m.len; + if (m.len > prevm.len) { + if (prevm.len) + recordlit(&s, prevc); + prevm = m; + prevc = *src; + step = 1; + } else if (prevm.len) { + recordmatch(&s, prevm); + step = prevm.len - 1; + prevm.len = 0; } else { recordlit(&s, *src); step = 1; } -*/ - if (m.len >= MinMatch) - if (m.len <= prevm.len) { - recordmatch(&s, prevm); - step = prevm.len - 1; - prevm.len = 0; - } else { - if (prevm.len > 0) - recordlit(&s, prevc); - prevm = m; - prevc = *src; - step = 1; - } - else - if (prevm.len > 0) { - recordmatch(&s, prevm); - step = prevm.len - 1; - prevm.len = 0; - } else { - recordlit(&s, *src); - step = 1; - } - while (step > 0) { if (len >= MinMatch) { hash = gethash(src);