changeset 67:b6646155e924

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.
author Rob Landley <rob@landley.net>
date Fri, 19 Jan 2007 16:01:54 -0500
parents d2c7f1cbd7d2
children 7b89650905c0
files lib/bunzip.c
diffstat 1 files changed, 9 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/lib/bunzip.c	Thu Jan 18 22:01:04 2007 -0500
+++ b/lib/bunzip.c	Fri Jan 19 16:01:54 2007 -0500
@@ -188,8 +188,15 @@
 				// !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;
 		}