aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-02-03 15:26:00 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-02-03 15:26:00 +0100
commit1cbcb023169abdb7ca278ae7c589c6f9fb60ca03 (patch)
tree078bbc4eb06ef3c8216bc2ac8d04037c4d3c9c7e
parentfc228b48c9fe2c5770d2f0059bb5027ff7dd159e (diff)
downloadbusybox-w32-1cbcb023169abdb7ca278ae7c589c6f9fb60ca03.tar.gz
busybox-w32-1cbcb023169abdb7ca278ae7c589c6f9fb60ca03.tar.bz2
busybox-w32-1cbcb023169abdb7ca278ae7c589c6f9fb60ca03.zip
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 a3b099f4b..0b614ce08 100644
--- a/archival/libarchive/bz/blocksort.c
+++ b/archival/libarchive/bz/blocksort.c
@@ -161,7 +161,7 @@ void fallbackQSort3(uint32_t* fmap,
161 ltLo++; 161 ltLo++;
162 unLo++; 162 unLo++;
163 continue; 163 continue;
164 }; 164 }
165 if (n > 0) break; 165 if (n > 0) break;
166 unLo++; 166 unLo++;
167 } 167 }
@@ -172,7 +172,7 @@ void fallbackQSort3(uint32_t* fmap,
172 mswap(fmap[unHi], fmap[gtHi]); 172 mswap(fmap[unHi], fmap[gtHi]);
173 gtHi--; unHi--; 173 gtHi--; unHi--;
174 continue; 174 continue;
175 }; 175 }
176 if (n < 0) break; 176 if (n < 0) break;
177 unHi--; 177 unHi--;
178 } 178 }
@@ -326,7 +326,7 @@ void fallbackSort(uint32_t* fmap,
326 if (cc != cc1) { 326 if (cc != cc1) {
327 SET_BH(i); 327 SET_BH(i);
328 cc = cc1; 328 cc = cc1;
329 }; 329 }
330 } 330 }
331 } 331 }
332 } 332 }
@@ -545,7 +545,7 @@ uint8_t mmed3(uint8_t a, uint8_t b, uint8_t c)
545 t = a; 545 t = a;
546 a = b; 546 a = b;
547 b = t; 547 b = t;
548 }; 548 }
549 /* here b >= a */ 549 /* here b >= a */
550 if (b > c) { 550 if (b > c) {
551 b = c; 551 b = c;
@@ -638,8 +638,8 @@ void mainQSort3(uint32_t* ptr,
638 ltLo++; 638 ltLo++;
639 unLo++; 639 unLo++;
640 continue; 640 continue;
641 }; 641 }
642 if (n > 0) break; 642 if (n > 0) break;
643 unLo++; 643 unLo++;
644 } 644 }
645 while (1) { 645 while (1) {
@@ -651,8 +651,8 @@ void mainQSort3(uint32_t* ptr,
651 gtHi--; 651 gtHi--;
652 unHi--; 652 unHi--;
653 continue; 653 continue;
654 }; 654 }
655 if (n < 0) break; 655 if (n < 0) break;
656 unHi--; 656 unHi--;
657 } 657 }
658 if (unLo > unHi) 658 if (unLo > unHi)
@@ -1063,7 +1063,7 @@ void BZ2_blockSort(EState* s)
1063 if (ptr[i] == 0) { 1063 if (ptr[i] == 0) {
1064 s->origPtr = i; 1064 s->origPtr = i;
1065 break; 1065 break;
1066 }; 1066 }
1067 1067
1068 AssertH(s->origPtr != -1, 1003); 1068 AssertH(s->origPtr != -1, 1003);
1069} 1069}
diff --git a/archival/libarchive/bz/compress.c b/archival/libarchive/bz/compress.c
index fc6af6595..7efa533b0 100644
--- a/archival/libarchive/bz/compress.c
+++ b/archival/libarchive/bz/compress.c
@@ -162,7 +162,7 @@ void generateMTFValues(EState* s)
162{ 162{
163 uint8_t yy[256]; 163 uint8_t yy[256];
164 int32_t i, j; 164 int32_t i, j;
165 int32_t zPend; 165 int zPend;
166 int32_t wr; 166 int32_t wr;
167 int32_t EOB; 167 int32_t EOB;
168 168
@@ -217,6 +217,7 @@ void generateMTFValues(EState* s)
217 if (zPend > 0) { 217 if (zPend > 0) {
218 zPend--; 218 zPend--;
219 while (1) { 219 while (1) {
220#if 0
220 if (zPend & 1) { 221 if (zPend & 1) {
221 mtfv[wr] = BZ_RUNB; wr++; 222 mtfv[wr] = BZ_RUNB; wr++;
222 s->mtfFreq[BZ_RUNB]++; 223 s->mtfFreq[BZ_RUNB]++;
@@ -224,10 +225,18 @@ void generateMTFValues(EState* s)
224 mtfv[wr] = BZ_RUNA; wr++; 225 mtfv[wr] = BZ_RUNA; wr++;
225 s->mtfFreq[BZ_RUNA]++; 226 s->mtfFreq[BZ_RUNA]++;
226 } 227 }
227 if (zPend < 2) break; 228#else /* same as above, since BZ_RUNA is 0 and BZ_RUNB is 1 */
228 zPend = (uint32_t)(zPend - 2) / 2; 229 unsigned run = zPend & 1;
230 mtfv[wr] = run;
231 wr++;
232 s->mtfFreq[run]++;
233#endif
234 zPend -= 2;
235 if (zPend < 0)
236 break;
237 zPend = (unsigned)zPend / 2;
229 /* bbox: unsigned div is easier */ 238 /* bbox: unsigned div is easier */
230 }; 239 }
231 zPend = 0; 240 zPend = 0;
232 } 241 }
233 { 242 {
@@ -244,7 +253,7 @@ void generateMTFValues(EState* s)
244 rtmp2 = rtmp; 253 rtmp2 = rtmp;
245 rtmp = *ryy_j; 254 rtmp = *ryy_j;
246 *ryy_j = rtmp2; 255 *ryy_j = rtmp2;
247 }; 256 }
248 yy[0] = rtmp; 257 yy[0] = rtmp;
249 j = ryy_j - &(yy[0]); 258 j = ryy_j - &(yy[0]);
250 mtfv[wr] = j+1; 259 mtfv[wr] = j+1;
@@ -257,6 +266,7 @@ void generateMTFValues(EState* s)
257 if (zPend > 0) { 266 if (zPend > 0) {
258 zPend--; 267 zPend--;
259 while (1) { 268 while (1) {
269#if 0
260 if (zPend & 1) { 270 if (zPend & 1) {
261 mtfv[wr] = BZ_RUNB; 271 mtfv[wr] = BZ_RUNB;
262 wr++; 272 wr++;
@@ -266,12 +276,18 @@ void generateMTFValues(EState* s)
266 wr++; 276 wr++;
267 s->mtfFreq[BZ_RUNA]++; 277 s->mtfFreq[BZ_RUNA]++;
268 } 278 }
269 if (zPend < 2) 279#else /* same as above, since BZ_RUNA is 0 and BZ_RUNB is 1 */
280 unsigned run = zPend & 1;
281 mtfv[wr] = run;
282 wr++;
283 s->mtfFreq[run]++;
284#endif
285 zPend -= 2;
286 if (zPend < 0)
270 break; 287 break;
271 zPend = (uint32_t)(zPend - 2) / 2; 288 zPend = (unsigned)zPend / 2;
272 /* bbox: unsigned div is easier */ 289 /* bbox: unsigned div is easier */
273 }; 290 }
274 zPend = 0;
275 } 291 }
276 292
277 mtfv[wr] = EOB; 293 mtfv[wr] = EOB;
@@ -528,11 +544,11 @@ void sendMTFValues(EState* s)
528 tmp2 = tmp; 544 tmp2 = tmp;
529 tmp = pos[j]; 545 tmp = pos[j];
530 pos[j] = tmp2; 546 pos[j] = tmp2;
531 }; 547 }
532 pos[0] = tmp; 548 pos[0] = tmp;
533 s->selectorMtf[i] = j; 549 s->selectorMtf[i] = j;
534 } 550 }
535 }; 551 }
536 552
537 /*--- Assign actual codes for the tables. --*/ 553 /*--- Assign actual codes for the tables. --*/
538 for (t = 0; t < nGroups; t++) { 554 for (t = 0; t < nGroups; t++) {
@@ -595,8 +611,8 @@ void sendMTFValues(EState* s)
595 unsigned curr = s->len[t][0]; 611 unsigned curr = s->len[t][0];
596 bsW(s, 5, curr); 612 bsW(s, 5, curr);
597 for (i = 0; i < alphaSize; i++) { 613 for (i = 0; i < alphaSize; i++) {
598 while (curr < s->len[t][i]) { bsW(s, 2, 2); curr++; /* 10 */ }; 614 while (curr < s->len[t][i]) { bsW(s, 2, 2); curr++; /* 10 */ }
599 while (curr > s->len[t][i]) { bsW(s, 2, 3); curr--; /* 11 */ }; 615 while (curr > s->len[t][i]) { bsW(s, 2, 3); curr--; /* 11 */ }
600 bsW1_0(s); 616 bsW1_0(s);
601 } 617 }
602 } 618 }
diff --git a/archival/libarchive/bz/huffman.c b/archival/libarchive/bz/huffman.c
index bbec11adb..be5930e00 100644
--- a/archival/libarchive/bz/huffman.c
+++ b/archival/libarchive/bz/huffman.c
@@ -217,7 +217,7 @@ void BZ2_hbAssignCodes(int32_t *code,
217 if (length[i] == n) { 217 if (length[i] == n) {
218 code[i] = vec; 218 code[i] = vec;
219 vec++; 219 vec++;
220 }; 220 }
221 } 221 }
222 vec <<= 1; 222 vec <<= 1;
223 } 223 }