bzip2: optimize zPend variable code
authorDenys Vlasenko <vda.linux@googlemail.com>
Sat, 3 Feb 2018 14:26:00 +0000 (15:26 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Sat, 3 Feb 2018 14:26:00 +0000 (15:26 +0100)
function                                             old     new   delta
generateMTFValues                                    433     378     -55

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
archival/libarchive/bz/blocksort.c
archival/libarchive/bz/compress.c
archival/libarchive/bz/huffman.c

index a3b099f4bd5af57334d34e03b835c32256473593..0b614ce08d98f5eb712bf06481b1dc019c0ac1b8 100644 (file)
@@ -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);
 }
index fc6af6595de4dc20ae60423cbfc534d7f8450a08..7efa533b0e727c3ca5859e4a3206d28abf381b04 100644 (file)
@@ -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);
                }
        }
index bbec11adbd1097f468806003bc85b1fbbcb1a927..be5930e00686750f4d374eea6fc813788e044697 100644 (file)
@@ -217,7 +217,7 @@ void BZ2_hbAssignCodes(int32_t *code,
                        if (length[i] == n) {
                                code[i] = vec;
                                vec++;
-                       };
+                       }
                }
                vec <<= 1;
        }