diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-01-07 19:39:34 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-01-07 19:39:34 +0000 |
commit | 1a03c21adfd1da80893aac75bb57094c702db031 (patch) | |
tree | d227ffc367c343f89e0377d914e4588268778b57 /archival/gzip.c | |
parent | da31fbc1b1dec08a18fc94d728b8d080f4a503d3 (diff) | |
download | busybox-w32-1a03c21adfd1da80893aac75bb57094c702db031.tar.gz busybox-w32-1a03c21adfd1da80893aac75bb57094c702db031.tar.bz2 busybox-w32-1a03c21adfd1da80893aac75bb57094c702db031.zip |
gzip cleanup part #6
Diffstat (limited to 'archival/gzip.c')
-rw-r--r-- | archival/gzip.c | 78 |
1 files changed, 45 insertions, 33 deletions
diff --git a/archival/gzip.c b/archival/gzip.c index 0ef25727d..758c70a4b 100644 --- a/archival/gzip.c +++ b/archival/gzip.c | |||
@@ -1476,7 +1476,7 @@ static void ct_init(ush * attr, int *methodp) | |||
1476 | for (code = 0; code < 16; code++) { | 1476 | for (code = 0; code < 16; code++) { |
1477 | base_dist[code] = dist; | 1477 | base_dist[code] = dist; |
1478 | for (n = 0; n < (1 << extra_dbits[code]); n++) { | 1478 | for (n = 0; n < (1 << extra_dbits[code]); n++) { |
1479 | dist_code[dist++] = (uch) code; | 1479 | dist_code[dist++] = code; |
1480 | } | 1480 | } |
1481 | } | 1481 | } |
1482 | Assert(dist == 256, "ct_init: dist != 256"); | 1482 | Assert(dist == 256, "ct_init: dist != 256"); |
@@ -1492,15 +1492,24 @@ static void ct_init(ush * attr, int *methodp) | |||
1492 | /* Construct the codes of the static literal tree */ | 1492 | /* Construct the codes of the static literal tree */ |
1493 | for (bits = 0; bits <= MAX_BITS; bits++) | 1493 | for (bits = 0; bits <= MAX_BITS; bits++) |
1494 | bl_count[bits] = 0; | 1494 | bl_count[bits] = 0; |
1495 | |||
1495 | n = 0; | 1496 | n = 0; |
1496 | while (n <= 143) | 1497 | while (n <= 143) { |
1497 | static_ltree[n++].Len = 8, bl_count[8]++; | 1498 | static_ltree[n++].Len = 8; |
1498 | while (n <= 255) | 1499 | bl_count[8]++; |
1499 | static_ltree[n++].Len = 9, bl_count[9]++; | 1500 | } |
1500 | while (n <= 279) | 1501 | while (n <= 255) { |
1501 | static_ltree[n++].Len = 7, bl_count[7]++; | 1502 | static_ltree[n++].Len = 9; |
1502 | while (n <= 287) | 1503 | bl_count[9]++; |
1503 | static_ltree[n++].Len = 8, bl_count[8]++; | 1504 | } |
1505 | while (n <= 279) { | ||
1506 | static_ltree[n++].Len = 7; | ||
1507 | bl_count[7]++; | ||
1508 | } | ||
1509 | while (n <= 287) { | ||
1510 | static_ltree[n++].Len = 8; | ||
1511 | bl_count[8]++; | ||
1512 | } | ||
1504 | /* Codes 286 and 287 do not exist, but we must include them in the | 1513 | /* Codes 286 and 287 do not exist, but we must include them in the |
1505 | * tree construction to get a canonical Huffman tree (longest code | 1514 | * tree construction to get a canonical Huffman tree (longest code |
1506 | * all ones) | 1515 | * all ones) |
@@ -1684,10 +1693,8 @@ static void gen_bitlen(tree_desc * desc) | |||
1684 | if (m > max_code) | 1693 | if (m > max_code) |
1685 | continue; | 1694 | continue; |
1686 | if (tree[m].Len != (unsigned) bits) { | 1695 | if (tree[m].Len != (unsigned) bits) { |
1687 | Trace((stderr, "code %d bits %d->%d\n", m, tree[m].Len, | 1696 | Trace((stderr, "code %d bits %d->%d\n", m, tree[m].Len, bits)); |
1688 | bits)); | 1697 | opt_len += ((long) bits - (long) tree[m].Len) * (long) tree[m].Freq; |
1689 | opt_len += | ||
1690 | ((long) bits - (long) tree[m].Len) * (long) tree[m].Freq; | ||
1691 | tree[m].Len = (ush) bits; | 1698 | tree[m].Len = (ush) bits; |
1692 | } | 1699 | } |
1693 | n--; | 1700 | n--; |
@@ -1846,8 +1853,10 @@ static void scan_tree(ct_data * tree, int max_code) | |||
1846 | int max_count = 7; /* max repeat count */ | 1853 | int max_count = 7; /* max repeat count */ |
1847 | int min_count = 4; /* min repeat count */ | 1854 | int min_count = 4; /* min repeat count */ |
1848 | 1855 | ||
1849 | if (nextlen == 0) | 1856 | if (nextlen == 0) { |
1850 | max_count = 138, min_count = 3; | 1857 | max_count = 138; |
1858 | min_count = 3; | ||
1859 | } | ||
1851 | tree[max_code + 1].Len = (ush) 0xffff; /* guard */ | 1860 | tree[max_code + 1].Len = (ush) 0xffff; /* guard */ |
1852 | 1861 | ||
1853 | for (n = 0; n <= max_code; n++) { | 1862 | for (n = 0; n <= max_code; n++) { |
@@ -1869,11 +1878,14 @@ static void scan_tree(ct_data * tree, int max_code) | |||
1869 | count = 0; | 1878 | count = 0; |
1870 | prevlen = curlen; | 1879 | prevlen = curlen; |
1871 | if (nextlen == 0) { | 1880 | if (nextlen == 0) { |
1872 | max_count = 138, min_count = 3; | 1881 | max_count = 138; |
1882 | min_count = 3; | ||
1873 | } else if (curlen == nextlen) { | 1883 | } else if (curlen == nextlen) { |
1874 | max_count = 6, min_count = 3; | 1884 | max_count = 6; |
1885 | min_count = 3; | ||
1875 | } else { | 1886 | } else { |
1876 | max_count = 7, min_count = 4; | 1887 | max_count = 7; |
1888 | min_count = 4; | ||
1877 | } | 1889 | } |
1878 | } | 1890 | } |
1879 | } | 1891 | } |
@@ -1904,8 +1916,7 @@ static void send_tree(ct_data * tree, int max_code) | |||
1904 | } else if (count < min_count) { | 1916 | } else if (count < min_count) { |
1905 | do { | 1917 | do { |
1906 | send_code(curlen, bl_tree); | 1918 | send_code(curlen, bl_tree); |
1907 | } while (--count != 0); | 1919 | } while (--count); |
1908 | |||
1909 | } else if (curlen != 0) { | 1920 | } else if (curlen != 0) { |
1910 | if (curlen != prevlen) { | 1921 | if (curlen != prevlen) { |
1911 | send_code(curlen, bl_tree); | 1922 | send_code(curlen, bl_tree); |
@@ -1914,11 +1925,9 @@ static void send_tree(ct_data * tree, int max_code) | |||
1914 | Assert(count >= 3 && count <= 6, " 3_6?"); | 1925 | Assert(count >= 3 && count <= 6, " 3_6?"); |
1915 | send_code(REP_3_6, bl_tree); | 1926 | send_code(REP_3_6, bl_tree); |
1916 | send_bits(count - 3, 2); | 1927 | send_bits(count - 3, 2); |
1917 | |||
1918 | } else if (count <= 10) { | 1928 | } else if (count <= 10) { |
1919 | send_code(REPZ_3_10, bl_tree); | 1929 | send_code(REPZ_3_10, bl_tree); |
1920 | send_bits(count - 3, 3); | 1930 | send_bits(count - 3, 3); |
1921 | |||
1922 | } else { | 1931 | } else { |
1923 | send_code(REPZ_11_138, bl_tree); | 1932 | send_code(REPZ_11_138, bl_tree); |
1924 | send_bits(count - 11, 7); | 1933 | send_bits(count - 11, 7); |
@@ -1926,11 +1935,14 @@ static void send_tree(ct_data * tree, int max_code) | |||
1926 | count = 0; | 1935 | count = 0; |
1927 | prevlen = curlen; | 1936 | prevlen = curlen; |
1928 | if (nextlen == 0) { | 1937 | if (nextlen == 0) { |
1929 | max_count = 138, min_count = 3; | 1938 | max_count = 138; |
1939 | min_count = 3; | ||
1930 | } else if (curlen == nextlen) { | 1940 | } else if (curlen == nextlen) { |
1931 | max_count = 6, min_count = 3; | 1941 | max_count = 6; |
1942 | min_count = 3; | ||
1932 | } else { | 1943 | } else { |
1933 | max_count = 7, min_count = 4; | 1944 | max_count = 7; |
1945 | min_count = 4; | ||
1934 | } | 1946 | } |
1935 | } | 1947 | } |
1936 | } | 1948 | } |
@@ -2046,7 +2058,7 @@ static ulg flush_block(char *buf, ulg stored_len, int eof) | |||
2046 | */ | 2058 | */ |
2047 | if (stored_len <= opt_lenb && eof && compressed_len == 0L && seekable()) { | 2059 | if (stored_len <= opt_lenb && eof && compressed_len == 0L && seekable()) { |
2048 | /* Since LIT_BUFSIZE <= 2*WSIZE, the input data must be there: */ | 2060 | /* Since LIT_BUFSIZE <= 2*WSIZE, the input data must be there: */ |
2049 | if (buf == (char *) 0) | 2061 | if (buf == NULL) |
2050 | bb_error_msg("block vanished"); | 2062 | bb_error_msg("block vanished"); |
2051 | 2063 | ||
2052 | copy_block(buf, (unsigned) stored_len, 0); /* without header */ | 2064 | copy_block(buf, (unsigned) stored_len, 0); /* without header */ |
@@ -2104,14 +2116,15 @@ static int ct_tally(int dist, int lc) | |||
2104 | } else { | 2116 | } else { |
2105 | /* Here, lc is the match length - MIN_MATCH */ | 2117 | /* Here, lc is the match length - MIN_MATCH */ |
2106 | dist--; /* dist = match distance - 1 */ | 2118 | dist--; /* dist = match distance - 1 */ |
2107 | Assert((ush) dist < (ush) MAX_DIST && | 2119 | Assert((ush) dist < (ush) MAX_DIST |
2108 | (ush) lc <= (ush) (MAX_MATCH - MIN_MATCH) && | 2120 | && (ush) lc <= (ush) (MAX_MATCH - MIN_MATCH) |
2109 | (ush) d_code(dist) < (ush) D_CODES, "ct_tally: bad match"); | 2121 | && (ush) d_code(dist) < (ush) D_CODES, "ct_tally: bad match" |
2122 | ); | ||
2110 | 2123 | ||
2111 | dyn_ltree[length_code[lc] + LITERALS + 1].Freq++; | 2124 | dyn_ltree[length_code[lc] + LITERALS + 1].Freq++; |
2112 | dyn_dtree[d_code(dist)].Freq++; | 2125 | dyn_dtree[d_code(dist)].Freq++; |
2113 | 2126 | ||
2114 | d_buf[last_dist++] = (ush) dist; | 2127 | d_buf[last_dist++] = dist; |
2115 | flags |= flag_bit; | 2128 | flags |= flag_bit; |
2116 | } | 2129 | } |
2117 | flag_bit <<= 1; | 2130 | flag_bit <<= 1; |
@@ -2124,13 +2137,12 @@ static int ct_tally(int dist, int lc) | |||
2124 | /* Try to guess if it is profitable to stop the current block here */ | 2137 | /* Try to guess if it is profitable to stop the current block here */ |
2125 | if ((last_lit & 0xfff) == 0) { | 2138 | if ((last_lit & 0xfff) == 0) { |
2126 | /* Compute an upper bound for the compressed length */ | 2139 | /* Compute an upper bound for the compressed length */ |
2127 | ulg out_length = (ulg) last_lit * 8L; | 2140 | ulg out_length = last_lit * 8L; |
2128 | ulg in_length = (ulg) strstart - block_start; | 2141 | ulg in_length = (ulg) strstart - block_start; |
2129 | int dcode; | 2142 | int dcode; |
2130 | 2143 | ||
2131 | for (dcode = 0; dcode < D_CODES; dcode++) { | 2144 | for (dcode = 0; dcode < D_CODES; dcode++) { |
2132 | out_length += | 2145 | out_length += dyn_dtree[dcode].Freq * (5L + extra_dbits[dcode]); |
2133 | (ulg) dyn_dtree[dcode].Freq * (5L + extra_dbits[dcode]); | ||
2134 | } | 2146 | } |
2135 | out_length >>= 3; | 2147 | out_length >>= 3; |
2136 | Trace((stderr, | 2148 | Trace((stderr, |