aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-10-14 01:37:53 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-10-14 01:37:53 +0000
commit9435993b01d789ebb984457ca2ba0eec627470db (patch)
tree9c9d11f6ebdc745525244bffcbd469fda018e0b4
parentbe5a7b965587307d8a7da7f8e35cb2470bf00dc4 (diff)
downloadbusybox-w32-9435993b01d789ebb984457ca2ba0eec627470db.tar.gz
busybox-w32-9435993b01d789ebb984457ca2ba0eec627470db.tar.bz2
busybox-w32-9435993b01d789ebb984457ca2ba0eec627470db.zip
bzip2: code size shrink
-rw-r--r--archival/bz/huffman.c38
1 files changed, 34 insertions, 4 deletions
diff --git a/archival/bz/huffman.c b/archival/bz/huffman.c
index 89e54604b..f016c968c 100644
--- a/archival/bz/huffman.c
+++ b/archival/bz/huffman.c
@@ -46,10 +46,16 @@ in the file LICENSE.
46 heap[zz] = tmp; \ 46 heap[zz] = tmp; \
47} 47}
48 48
49#define DOWNHEAP(z) \ 49
50/* 90 bytes, 0.3% of overall compress speed */
51#if CONFIG_BZIP2_FEATURE_SPEED >= 1
52
53/* macro works better than inline (gcc 4.2.1) */
54#define DOWNHEAP1(heap, weight, Heap) \
50{ \ 55{ \
51 int32_t zz, yy, tmp; \ 56 int32_t zz, yy, tmp; \
52 zz = z; tmp = heap[zz]; \ 57 zz = 1; \
58 tmp = heap[zz]; \
53 while (1) { \ 59 while (1) { \
54 yy = zz << 1; \ 60 yy = zz << 1; \
55 if (yy > nHeap) \ 61 if (yy > nHeap) \
@@ -65,6 +71,30 @@ in the file LICENSE.
65 heap[zz] = tmp; \ 71 heap[zz] = tmp; \
66} 72}
67 73
74#else
75
76static
77void DOWNHEAP1(int32_t *heap, int32_t *weight, int32_t nHeap)
78{
79 int32_t zz, yy, tmp;
80 zz = 1;
81 tmp = heap[zz];
82 while (1) {
83 yy = zz << 1;
84 if (yy > nHeap)
85 break;
86 if (yy < nHeap
87 && weight[heap[yy + 1]] < weight[heap[yy]])
88 yy++;
89 if (weight[tmp] < weight[heap[yy]])
90 break;
91 heap[zz] = heap[yy];
92 zz = yy;
93 }
94 heap[zz] = tmp;
95}
96
97#endif
68 98
69/*---------------------------------------------------*/ 99/*---------------------------------------------------*/
70static 100static
@@ -105,8 +135,8 @@ void BZ2_hbMakeCodeLengths(uint8_t *len,
105 AssertH(nHeap < (BZ_MAX_ALPHA_SIZE+2), 2001); 135 AssertH(nHeap < (BZ_MAX_ALPHA_SIZE+2), 2001);
106 136
107 while (nHeap > 1) { 137 while (nHeap > 1) {
108 n1 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP(1); 138 n1 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP1(heap, weight, nHeap);
109 n2 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP(1); 139 n2 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP1(heap, weight, nHeap);
110 nNodes++; 140 nNodes++;
111 parent[n1] = parent[n2] = nNodes; 141 parent[n1] = parent[n2] = nNodes;
112 weight[nNodes] = ADDWEIGHTS(weight[n1], weight[n2]); 142 weight[nNodes] = ADDWEIGHTS(weight[n1], weight[n2]);