commit 0c8559e47e28462e087102babc34257c9b1aa30f
parent 2dd84d164143d185cb9edd664bed5f2a4e71c969
Author: nsz <nszabolcs@gmail.com>
Date: Sun, 16 Aug 2009 13:53:56 +0200
deflate clean up
Diffstat:
1 file changed, 7 insertions(+), 11 deletions(-)
diff --git a/deflate.c b/deflate.c
@@ -2,8 +2,6 @@
#include <string.h>
#include "flate.h"
-#include <stdio.h>
-
enum {
CodeBits = 16, /* max number of bits in a code + 1 */
EOB = 256, /* end of block symbol */
@@ -328,7 +326,7 @@ static void deflate_block(State *s) {
uchar *h;
int dynsize, fixsize, uncsize;
int blocklen = s->pos - s->startpos;
-int dyntree;
+/* int dyntree; */
/* calc dynamic codes */
hufflens(llen, s->lfreq, Nlitlen, CodeBits-1);
@@ -359,7 +357,7 @@ int dyntree;
if (c == 18)
dynsize += 7;
}
-dyntree = dynsize - 3;
+/* dyntree = dynsize - 3; */
for (lz = s->lzbuf, h = s->hist + s->startpos; lz != s->lz; lz++)
if (lz->bits & LzLitFlag)
for (n = lz->n; n > 0; n--, h++) {
@@ -416,11 +414,11 @@ dyntree = dynsize - 3;
memcpy(s->dst, s->hist + s->startpos, blocklen);
s->dst += blocklen;
}
-
+/*
fprintf(stderr, "blen:%d [%d,%d] lzlen:%d dynlen:%d (tree:%d rate:%.3f) fixlen:%d (rate:%.3f) unclen:%d (rate:%.3f) avail:%d\n",
blocklen, s->startpos, s->pos, s->lz - s->lzbuf, dynsize, dyntree, dynsize/(float)blocklen,
fixsize, fixsize/(float)blocklen, uncsize, uncsize/(float)blocklen, s->avail);
-
+*/
}
/* find n in base */
@@ -539,7 +537,7 @@ static void newblock(State *s) {
correctness assertions:
- pos < 64K in updatechain (head and chain is ushort)
- updatechain has at least MinMatch input (except at eof)
- - getmatch has at least MaxMatch input
+ - getmatch has at least MaxMatch input in hist
- getmatch has at least HistSafe history
- lzbuf does not overflow before endblock
- dstbuf does not overflow before endblock
@@ -551,8 +549,6 @@ correctness assertions:
static int updatehist(State *s) {
int n, k;
- if (s->avail > HistEnd)
- return 1;
if (s->pos >= HistSize - HistEnd) {
/* shift hist */
memcpy(s->hist, s->hist + WinSize, HistSize - WinSize);
@@ -563,10 +559,10 @@ static int updatehist(State *s) {
s->startpos -= WinSize;
s->pos -= WinSize;
}
- if (!s->eof) {
+ if (s->avail <= HistEnd && !s->eof) {
/* fill hist */
k = s->srcend - s->src;
- n = HistSize - s->pos - s->avail; /* s->avail + n >= MaxMatch */
+ n = HistSize - s->pos - s->avail; /* s->avail + n > HistEnd */
if (k > n)
k = n;
memcpy(s->hist + s->pos + s->avail, s->src, k);