aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2007-01-19 16:01:54 -0500
committerRob Landley <rob@landley.net>2007-01-19 16:01:54 -0500
commit59b301786890b909d64ddc61e279394184fd57d7 (patch)
treed0c215cb05fddda2b0d6ae87642a1c355a8ffa2a
parente790130c2141257c7d230c09934fac119d750f44 (diff)
downloadtoybox-59b301786890b909d64ddc61e279394184fd57d7.tar.gz
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.
-rw-r--r--lib/bunzip.c11
1 files 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;
}