summaryrefslogtreecommitdiff
path: root/inffast.c
diff options
context:
space:
mode:
authorZhaoxiu Zeng <zhaoxiu.zeng@gmail.com>2014-07-27 16:29:58 +0800
committerhansr <hk-git@circlestorm.org>2014-10-13 13:26:20 +0200
commit47c91930fa572b4ce58d083edeb12fdd7f1a63b9 (patch)
tree0c671f60eb1d58531bb1d75788a26c23f11c5696 /inffast.c
parent4ebc9be9cd1f7c2477ebe590aaa6255be2a1eca1 (diff)
inffast.c: add BITS and DROPBITS macros like inflate.c
Diffstat (limited to 'inffast.c')
-rw-r--r--inffast.c33
1 files changed, 19 insertions, 14 deletions
diff --git a/inffast.c b/inffast.c
index a3200f3..6b82c83 100644
--- a/inffast.c
+++ b/inffast.c
@@ -29,6 +29,17 @@
# define PUP(a) *++(a)
#endif
+/* Return the low n bits of the bit accumulator (n < 16) */
+#define BITS(n) \
+ ((unsigned)hold & ((1U << (n)) - 1))
+
+/* Remove n bits from the bit accumulator */
+#define DROPBITS(n) \
+ do { \
+ hold >>= (n); \
+ bits -= (unsigned)(n); \
+ } while (0)
+
/*
Decode literal, length, and distance codes and write out the resulting
literal and match bytes until either not enough input or output is
@@ -126,9 +137,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
}
here = lcode[hold & lmask];
dolen:
- op = (unsigned)(here.bits);
- hold >>= op;
- bits -= op;
+ DROPBITS(here.bits);
op = (unsigned)(here.op);
if (op == 0) { /* literal */
Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
@@ -144,9 +153,8 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
hold += (unsigned long)(PUP(in)) << bits;
bits += 8;
}
- len += (unsigned)hold & ((1U << op) - 1);
- hold >>= op;
- bits -= op;
+ len += BITS(op);
+ DROPBITS(op);
}
Tracevv((stderr, "inflate: length %u\n", len));
if (bits < 15) {
@@ -157,9 +165,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
}
here = dcode[hold & dmask];
dodist:
- op = (unsigned)(here.bits);
- hold >>= op;
- bits -= op;
+ DROPBITS(here.bits);
op = (unsigned)(here.op);
if (op & 16) { /* distance base */
dist = (unsigned)(here.val);
@@ -172,7 +178,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
bits += 8;
}
}
- dist += (unsigned)hold & ((1U << op) - 1);
+ dist += BITS(op);
#ifdef INFLATE_STRICT
if (dist > dmax) {
strm->msg = (char *)"invalid distance too far back";
@@ -180,8 +186,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
break;
}
#endif
- hold >>= op;
- bits -= op;
+ DROPBITS(op);
Tracevv((stderr, "inflate: distance %u\n", dist));
op = (unsigned)(out - beg); /* max distance in output */
if (dist > op) { /* see if copy from window */
@@ -281,7 +286,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
}
}
else if ((op & 64) == 0) { /* 2nd level distance code */
- here = dcode[here.val + (hold & ((1U << op) - 1))];
+ here = dcode[here.val + BITS(op)];
goto dodist;
}
else {
@@ -291,7 +296,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
}
}
else if ((op & 64) == 0) { /* 2nd level length code */
- here = lcode[here.val + (hold & ((1U << op) - 1))];
+ here = lcode[here.val + BITS(op)];
goto dolen;
}
else if (op & 32) { /* end-of-block */