flate

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

commit 8fba42f347be7bb505324c2d57847807a7ba26a3
parent c338151a0cb5cb8f46fb9b82e02dc90400c77e60
Author: nsz <nszabolcs@gmail.com>
Date:   Mon,  8 Jun 2009 11:26:02 +0200

renames
Diffstat:
inflate.c | 39++++++++++++++-------------------------
1 file changed, 14 insertions(+), 25 deletions(-)

diff --git a/inflate.c b/inflate.c @@ -219,26 +219,7 @@ static void init_fixed_huffs(void) { build_huff(&dhuff, lens, Ndist, 5); } -static int fillbits(State *s, int n) { - while (s->nbits < n) { - if (s->src == s->srcend) - return 0; - s->bits |= *s->src++ << s->nbits; - s->nbits += 8; - } - return 1; -} - -static uint getbits(State *s, int n) { - uint k; - - k = s->bits & ((1 << n) - 1); - s->bits >>= n; - s->nbits -= n; - return k; -} - -static int fillbits_(uchar **src, uchar *srcend, uint *bits, uint *nbits, uint n) { +static int fillbits_fast(uchar **src, uchar *srcend, uint *bits, uint *nbits, uint n) { while (*nbits < n) { if (*src == srcend) return 0; @@ -248,7 +229,7 @@ static int fillbits_(uchar **src, uchar *srcend, uint *bits, uint *nbits, uint n return 1; } -static uint getbits_(uint *bits, uint *nbits, int n) { +static uint getbits_fast(uint *bits, uint *nbits, int n) { uint k; k = *bits & ((1 << n) - 1); @@ -257,6 +238,14 @@ static uint getbits_(uint *bits, uint *nbits, int n) { return k; } +static int fillbits(State *s, uint n) { + return fillbits_fast(&s->src, s->srcend, &s->bits, &s->nbits, n); +} + +static uint getbits(State *s, uint n) { + return getbits_fast(&s->bits, &s->nbits, n); +} + /* decode symbol bitwise if code is longer than huffbits */ static uint decode_symbol_long(State *s, Huff *huff, uint bits, uint nbits, int cur) { int sum = huff->sum; @@ -387,13 +376,13 @@ static int decode_block(State *s, Huff *lhuff, Huff *dhuff) { return FlateError; } decode_lenbits: - if (!fillbits_(&s->src, s->srcend, &s->bits, &s->nbits, lenbits[sym])) { + if (!fillbits_fast(&s->src, s->srcend, &s->bits, &s->nbits, lenbits[sym])) { s->nclen = sym; /* using nclen to store sym */ s->pos = pos; s->state = DecodeBlockLenBits; return FlateNeedInput; } - len = lenbase[sym] + getbits_(&s->bits, &s->nbits, lenbits[sym]); + len = lenbase[sym] + getbits_fast(&s->bits, &s->nbits, lenbits[sym]); decode_dist: sym = decode_symbol(s, dhuff); if (sym == (uint)FlateNeedInput) { @@ -405,7 +394,7 @@ decode_dist: if (sym >= Ndist) return FlateError; decode_distbits: - if (!fillbits_(&s->src, s->srcend, &s->bits, &s->nbits, distbits[sym])) { + if (!fillbits_fast(&s->src, s->srcend, &s->bits, &s->nbits, distbits[sym])) { s->nclen = sym; /* using nclen to store sym */ s->pos = pos; s->lenpos = len; @@ -413,7 +402,7 @@ decode_distbits: return FlateNeedInput; } /* TODO: s/dist/sym/ */ - dist = distbase[sym] + getbits_(&s->bits, &s->nbits, distbits[sym]); + dist = distbase[sym] + getbits_fast(&s->bits, &s->nbits, distbits[sym]); /* copy match, loop unroll in common case */ if (pos + len < WinSize) { /* lenbase[sym] >= 3 */