From 59b301786890b909d64ddc61e279394184fd57d7 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Fri, 19 Jan 2007 16:01:54 -0500 Subject: Another suggestion from Manuel: Grab 2 bits instead of 1 inside a loop. Saves 4 bytes and reduces running time by one half of one percent. --- lib/bunzip.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/bunzip.c b/lib/bunzip.c index 96f7a871..7804b7fa 100644 --- a/lib/bunzip.c +++ b/lib/bunzip.c @@ -188,8 +188,15 @@ int read_bunzip_data(bunzip_data *bd) // !t || t > MAX_HUFCODE_BITS in one test. if (MAX_HUFCODE_BITS-1 < (unsigned)t-1) return RETVAL_DATA_ERROR; - if(!get_bits(bd, 1)) break; // Stop yet? - t += (1 - 2*get_bits(bd, 1)); // bit ? t-- : t++ + // Grab 2 bits instead of 1 (slightly smaller/faster). Stop if + // first bit is 0, otherwise second bit says whether to + // increment or decrement. + k = get_bits(bd, 2); + if (k & 2) t += 1 - ((k&1)<<1); + else { + bd->inbufBitCount++; + break; + } } length[i] = t; } -- cgit v1.2.3