flate

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

commit 11d9b69b27faa3b4cdc3dff28364871582c8ee53
parent 91f4e002ef67509b758a6765a35bba94b13688cd
Author: nsz <nszabolcs@gmail.com>
Date:   Thu, 16 Jul 2009 14:20:21 +0200

fix unc block bug
Diffstat:
Makefile | 17++++++++++++-----
deflate_simple.c | 12++++++++----
2 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/Makefile b/Makefile @@ -23,11 +23,18 @@ clean: prof: inflate.c gcc -O3 -fprofile-arcs -ftest-coverage -pg -g -Wall $< - cat a.dat | ./a.out > /dev/null - gcov -b $< > /dev/null - gprof a.out > $<.gprof - gcc -g -Wall $< -# cat d.dat | valgrind -v --leak-check=yes ./a.out > /dev/null 2> a.valgrind + ./a.out <a.dat >/dev/null + gcov -b $< >/dev/null + gprof a.out >$<.gprof +# gcc -g -Wall $< +# valgrind -v --leak-check=yes ./a.out <a.dat >/dev/null 2>a.valgrind # grep ERROR a.valgrind # grep alloc a.valgrind rm -f a.out a.valgrind *.gcno *.gcda gmon.out + +profdef: deflate_simple.c + gcc -O0 -fprofile-arcs -ftest-coverage -pg -g -Wall $< + ./a.out <a.pdf >/dev/null + gcov -b $< >/dev/null + gprof a.out >$<.gprof + rm -f a.out *.gcno *.gcda gmon.out diff --git a/deflate_simple.c b/deflate_simple.c @@ -330,6 +330,7 @@ static void deflate_block(State *s, int blocklen) { int dynsize, fixsize, uncsize; int *p; uchar *plit; +int dyntree; hufflens(llen, s->lfreq, Nlitlen, CodeBits-1); hufflens(dlen, s->dfreq, Ndist, CodeBits-1); @@ -346,7 +347,7 @@ static void deflate_block(State *s, int blocklen) { for (nclen = Nclen; nclen > 4 && clen[clenorder[nclen-1]] == 0; nclen--); /* calc size */ - uncsize = 3 + 16 + 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; @@ -360,6 +361,7 @@ static void deflate_block(State *s, int blocklen) { if (c == 18) dynsize += 7; } +dyntree = dynsize - 3; /* TODO: */ for (p = s->lzbuf, plit = s->src; p != s->lzp;) { c = *p++; @@ -417,10 +419,12 @@ static void deflate_block(State *s, int blocklen) { putbits(s, 0, 7); /* align to byte boundary */ s->nbits = 0; putbits(s, blocklen, 16); - putbits(s, ~blocklen, 16); + putbits(s, ~blocklen & 0xffff, 16); memcpy(s->dst, s->src, blocklen); + s->dst += blocklen; } -fprintf(stderr, "blocklen: %d lzlen: %d dynsize: %d fixsize: %d uncsize: %d\n", blocklen, s->lzp - s->lzbuf, dynsize, fixsize, uncsize); +fprintf(stderr, "blocklen: %d lzlen: %d dynsize: %d (tree: %d, rate: %.3f) fixsize: %d (rate: %.3f) uncsize: %d (rate: %.3f)\n", blocklen, s->lzp - s->lzbuf, + dynsize, dyntree, dynsize/(float)blocklen, fixsize, fixsize/(float)blocklen, uncsize, uncsize/(float)blocklen); } @@ -491,7 +495,7 @@ static Match getmatch(State *s, uchar *src, int len) { } pos = s->chain[pos]; } - if (m.len < MinMatch || (m.len == MinMatch && m.dist > 1<<13)) + if (m.len < MinMatch || (m.len == MinMatch && m.dist > 1<<12)) m.len = 0; return m; }