changeset 55:0bb7c679499a

Memmove is 11 bytes shorter than the unrolled loop, and Manuel Nova pointed out how to turn an if/else into a multiply and subtract (saving 2 bytes).
author Rob Landley <rob@landley.net>
date Tue, 16 Jan 2007 14:25:12 -0500
parents 60a7fb8ddeb4
children 7794562e2e64
files lib/bunzip.c
diffstat 1 files changed, 3 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/lib/bunzip.c	Tue Jan 16 13:26:02 2007 -0500
+++ b/lib/bunzip.c	Tue Jan 16 14:25:12 2007 -0500
@@ -182,7 +182,7 @@
 
 		// Decode MTF to get the next selector
 		uc = mtfSymbol[j];
-		for (k=j; k; k--) mtfSymbol[k] = mtfSymbol[k-1];
+		memmove(mtfSymbol+1, mtfSymbol, j);
 		mtfSymbol[0] = selectors[i] = uc;
 	}
 	// Read the huffman coding tables for each group, which code for symTotal
@@ -197,9 +197,8 @@
 		for (i = 0; i < symCount; i++) {
 			for(;;) {
 				if (MAX_HUFCODE_BITS < (unsigned)t-1) return RETVAL_DATA_ERROR;
-				if(!get_bits(bd, 1)) break;
-				if(!get_bits(bd, 1)) t++;
-				else t--;
+				if(!get_bits(bd, 1)) break;    // Stop yet?
+				t += (1 - 2*get_bits(bd, 1));  // bit ? t-- : t++
 			}
 			length[i] = t;
 		}