summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko2018-02-03 15:26:00 +0100
committerDenys Vlasenko2018-02-03 15:26:00 +0100
commit1cbcb023169abdb7ca278ae7c589c6f9fb60ca03 (patch)
tree078bbc4eb06ef3c8216bc2ac8d04037c4d3c9c7e
parentfc228b48c9fe2c5770d2f0059bb5027ff7dd159e (diff)
downloadbusybox-1cbcb023169abdb7ca278ae7c589c6f9fb60ca03.zip
busybox-1cbcb023169abdb7ca278ae7c589c6f9fb60ca03.tar.gz
bzip2: optimize zPend variable code
function old new delta generateMTFValues 433 378 -55 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--archival/libarchive/bz/blocksort.c18
-rw-r--r--archival/libarchive/bz/compress.c42
-rw-r--r--archival/libarchive/bz/huffman.c2
3 files changed, 39 insertions, 23 deletions
diff --git a/archival/libarchive/bz/blocksort.c b/archival/libarchive/bz/blocksort.c
index a3b099f..0b614ce 100644
--- a/archival/libarchive/bz/blocksort.c
+++ b/archival/libarchive/bz/blocksort.c
@@ -161,7 +161,7 @@ void fallbackQSort3(uint32_t* fmap,
ltLo++;
unLo++;
continue;
- };
+ }
if (n > 0) break;
unLo++;
}
@@ -172,7 +172,7 @@ void fallbackQSort3(uint32_t* fmap,
mswap(fmap[unHi], fmap[gtHi]);
gtHi--; unHi--;
continue;
- };
+ }
if (n < 0) break;
unHi--;
}
@@ -326,7 +326,7 @@ void fallbackSort(uint32_t* fmap,
if (cc != cc1) {
SET_BH(i);
cc = cc1;
- };
+ }
}
}
}
@@ -545,7 +545,7 @@ uint8_t mmed3(uint8_t a, uint8_t b, uint8_t c)
t = a;
a = b;
b = t;
- };
+ }
/* here b >= a */
if (b > c) {
b = c;
@@ -638,8 +638,8 @@ void mainQSort3(uint32_t* ptr,
ltLo++;
unLo++;
continue;
- };
- if (n > 0) break;
+ }
+ if (n > 0) break;
unLo++;
}
while (1) {
@@ -651,8 +651,8 @@ void mainQSort3(uint32_t* ptr,
gtHi--;
unHi--;
continue;
- };
- if (n < 0) break;
+ }
+ if (n < 0) break;
unHi--;
}
if (unLo > unHi)
@@ -1063,7 +1063,7 @@ void BZ2_blockSort(EState* s)
if (ptr[i] == 0) {
s->origPtr = i;
break;
- };
+ }
AssertH(s->origPtr != -1, 1003);
}
diff --git a/archival/libarchive/bz/compress.c b/archival/libarchive/bz/compress.c
index fc6af65..7efa533 100644
--- a/archival/libarchive/bz/compress.c
+++ b/archival/libarchive/bz/compress.c
@@ -162,7 +162,7 @@ void generateMTFValues(EState* s)
{
uint8_t yy[256];
int32_t i, j;
- int32_t zPend;
+ int zPend;
int32_t wr;
int32_t EOB;
@@ -217,6 +217,7 @@ void generateMTFValues(EState* s)
if (zPend > 0) {
zPend--;
while (1) {
+#if 0
if (zPend & 1) {
mtfv[wr] = BZ_RUNB; wr++;
s->mtfFreq[BZ_RUNB]++;
@@ -224,10 +225,18 @@ void generateMTFValues(EState* s)
mtfv[wr] = BZ_RUNA; wr++;
s->mtfFreq[BZ_RUNA]++;
}
- if (zPend < 2) break;
- zPend = (uint32_t)(zPend - 2) / 2;
+#else /* same as above, since BZ_RUNA is 0 and BZ_RUNB is 1 */
+ unsigned run = zPend & 1;
+ mtfv[wr] = run;
+ wr++;
+ s->mtfFreq[run]++;
+#endif
+ zPend -= 2;
+ if (zPend < 0)
+ break;
+ zPend = (unsigned)zPend / 2;
/* bbox: unsigned div is easier */
- };
+ }
zPend = 0;
}
{
@@ -244,7 +253,7 @@ void generateMTFValues(EState* s)
rtmp2 = rtmp;
rtmp = *ryy_j;
*ryy_j = rtmp2;
- };
+ }
yy[0] = rtmp;
j = ryy_j - &(yy[0]);
mtfv[wr] = j+1;
@@ -257,6 +266,7 @@ void generateMTFValues(EState* s)
if (zPend > 0) {
zPend--;
while (1) {
+#if 0
if (zPend & 1) {
mtfv[wr] = BZ_RUNB;
wr++;
@@ -266,12 +276,18 @@ void generateMTFValues(EState* s)
wr++;
s->mtfFreq[BZ_RUNA]++;
}
- if (zPend < 2)
+#else /* same as above, since BZ_RUNA is 0 and BZ_RUNB is 1 */
+ unsigned run = zPend & 1;
+ mtfv[wr] = run;
+ wr++;
+ s->mtfFreq[run]++;
+#endif
+ zPend -= 2;
+ if (zPend < 0)
break;
- zPend = (uint32_t)(zPend - 2) / 2;
+ zPend = (unsigned)zPend / 2;
/* bbox: unsigned div is easier */
- };
- zPend = 0;
+ }
}
mtfv[wr] = EOB;
@@ -528,11 +544,11 @@ void sendMTFValues(EState* s)
tmp2 = tmp;
tmp = pos[j];
pos[j] = tmp2;
- };
+ }
pos[0] = tmp;
s->selectorMtf[i] = j;
}
- };
+ }
/*--- Assign actual codes for the tables. --*/
for (t = 0; t < nGroups; t++) {
@@ -595,8 +611,8 @@ void sendMTFValues(EState* s)
unsigned curr = s->len[t][0];
bsW(s, 5, curr);
for (i = 0; i < alphaSize; i++) {
- while (curr < s->len[t][i]) { bsW(s, 2, 2); curr++; /* 10 */ };
- while (curr > s->len[t][i]) { bsW(s, 2, 3); curr--; /* 11 */ };
+ while (curr < s->len[t][i]) { bsW(s, 2, 2); curr++; /* 10 */ }
+ while (curr > s->len[t][i]) { bsW(s, 2, 3); curr--; /* 11 */ }
bsW1_0(s);
}
}
diff --git a/archival/libarchive/bz/huffman.c b/archival/libarchive/bz/huffman.c
index bbec11a..be5930e 100644
--- a/archival/libarchive/bz/huffman.c
+++ b/archival/libarchive/bz/huffman.c
@@ -217,7 +217,7 @@ void BZ2_hbAssignCodes(int32_t *code,
if (length[i] == n) {
code[i] = vec;
vec++;
- };
+ }
}
vec <<= 1;
}