diff options
| author | Mark Adler <madler@alumni.caltech.edu> | 2011-09-09 23:19:55 -0700 |
|---|---|---|
| committer | Mark Adler <madler@alumni.caltech.edu> | 2011-09-09 23:19:55 -0700 |
| commit | 965fe72aed580d518c979c9a33b49e7df28205f7 (patch) | |
| tree | d2471c968f71224c415a9b6cb3b4ca01bd0a94ab /trees.c | |
| parent | b8c9ecb0765fc39423c07613d909c5193378bdfd (diff) | |
| download | zlib-965fe72aed580d518c979c9a33b49e7df28205f7.tar.gz zlib-965fe72aed580d518c979c9a33b49e7df28205f7.tar.bz2 zlib-965fe72aed580d518c979c9a33b49e7df28205f7.zip | |
zlib 1.1.0v1.1.0
Diffstat (limited to '')
| -rw-r--r-- | trees.c | 31 |
1 files changed, 12 insertions, 19 deletions
| @@ -99,13 +99,13 @@ local ct_data static_dtree[D_CODES]; | |||
| 99 | * 5 bits.) | 99 | * 5 bits.) |
| 100 | */ | 100 | */ |
| 101 | 101 | ||
| 102 | local uch dist_code[DIST_CODE_LEN]; | 102 | uch _dist_code[DIST_CODE_LEN]; |
| 103 | /* Distance codes. The first 256 values correspond to the distances | 103 | /* Distance codes. The first 256 values correspond to the distances |
| 104 | * 3 .. 258, the last 256 values correspond to the top 8 bits of | 104 | * 3 .. 258, the last 256 values correspond to the top 8 bits of |
| 105 | * the 15 bit distances. | 105 | * the 15 bit distances. |
| 106 | */ | 106 | */ |
| 107 | 107 | ||
| 108 | local uch length_code[MAX_MATCH-MIN_MATCH+1]; | 108 | uch _length_code[MAX_MATCH-MIN_MATCH+1]; |
| 109 | /* length code for each normalized match length (0 == MIN_MATCH) */ | 109 | /* length code for each normalized match length (0 == MIN_MATCH) */ |
| 110 | 110 | ||
| 111 | local int base_length[LENGTH_CODES]; | 111 | local int base_length[LENGTH_CODES]; |
| @@ -173,13 +173,6 @@ local void gen_trees_header OF((void)); | |||
| 173 | send_bits(s, tree[c].Code, tree[c].Len); } | 173 | send_bits(s, tree[c].Code, tree[c].Len); } |
| 174 | #endif | 174 | #endif |
| 175 | 175 | ||
| 176 | #define d_code(dist) \ | ||
| 177 | ((dist) < 256 ? dist_code[dist] : dist_code[256+((dist)>>7)]) | ||
| 178 | /* Mapping from a distance to a distance code. dist is the distance - 1 and | ||
| 179 | * must not have side effects. dist_code[256] and dist_code[257] are never | ||
| 180 | * used. | ||
| 181 | */ | ||
| 182 | |||
| 183 | /* =========================================================================== | 176 | /* =========================================================================== |
| 184 | * Output a short LSB first on the stream. | 177 | * Output a short LSB first on the stream. |
| 185 | * IN assertion: there is enough room in pendingBuf. | 178 | * IN assertion: there is enough room in pendingBuf. |
| @@ -262,7 +255,7 @@ local void tr_static_init() | |||
| 262 | for (code = 0; code < LENGTH_CODES-1; code++) { | 255 | for (code = 0; code < LENGTH_CODES-1; code++) { |
| 263 | base_length[code] = length; | 256 | base_length[code] = length; |
| 264 | for (n = 0; n < (1<<extra_lbits[code]); n++) { | 257 | for (n = 0; n < (1<<extra_lbits[code]); n++) { |
| 265 | length_code[length++] = (uch)code; | 258 | _length_code[length++] = (uch)code; |
| 266 | } | 259 | } |
| 267 | } | 260 | } |
| 268 | Assert (length == 256, "tr_static_init: length != 256"); | 261 | Assert (length == 256, "tr_static_init: length != 256"); |
| @@ -270,14 +263,14 @@ local void tr_static_init() | |||
| 270 | * in two different ways: code 284 + 5 bits or code 285, so we | 263 | * in two different ways: code 284 + 5 bits or code 285, so we |
| 271 | * overwrite length_code[255] to use the best encoding: | 264 | * overwrite length_code[255] to use the best encoding: |
| 272 | */ | 265 | */ |
| 273 | length_code[length-1] = (uch)code; | 266 | _length_code[length-1] = (uch)code; |
| 274 | 267 | ||
| 275 | /* Initialize the mapping dist (0..32K) -> dist code (0..29) */ | 268 | /* Initialize the mapping dist (0..32K) -> dist code (0..29) */ |
| 276 | dist = 0; | 269 | dist = 0; |
| 277 | for (code = 0 ; code < 16; code++) { | 270 | for (code = 0 ; code < 16; code++) { |
| 278 | base_dist[code] = dist; | 271 | base_dist[code] = dist; |
| 279 | for (n = 0; n < (1<<extra_dbits[code]); n++) { | 272 | for (n = 0; n < (1<<extra_dbits[code]); n++) { |
| 280 | dist_code[dist++] = (uch)code; | 273 | _dist_code[dist++] = (uch)code; |
| 281 | } | 274 | } |
| 282 | } | 275 | } |
| 283 | Assert (dist == 256, "tr_static_init: dist != 256"); | 276 | Assert (dist == 256, "tr_static_init: dist != 256"); |
| @@ -285,7 +278,7 @@ local void tr_static_init() | |||
| 285 | for ( ; code < D_CODES; code++) { | 278 | for ( ; code < D_CODES; code++) { |
| 286 | base_dist[code] = dist << 7; | 279 | base_dist[code] = dist << 7; |
| 287 | for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) { | 280 | for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) { |
| 288 | dist_code[256 + dist++] = (uch)code; | 281 | _dist_code[256 + dist++] = (uch)code; |
| 289 | } | 282 | } |
| 290 | } | 283 | } |
| 291 | Assert (dist == 256, "tr_static_init: 256+dist != 512"); | 284 | Assert (dist == 256, "tr_static_init: 256+dist != 512"); |
| @@ -349,15 +342,15 @@ void gen_trees_header() | |||
| 349 | static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5)); | 342 | static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5)); |
| 350 | } | 343 | } |
| 351 | 344 | ||
| 352 | fprintf(header, "local const uch dist_code[DIST_CODE_LEN] = {\n"); | 345 | fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n"); |
| 353 | for (i = 0; i < DIST_CODE_LEN; i++) { | 346 | for (i = 0; i < DIST_CODE_LEN; i++) { |
| 354 | fprintf(header, "%2u%s", dist_code[i], | 347 | fprintf(header, "%2u%s", _dist_code[i], |
| 355 | SEPARATOR(i, DIST_CODE_LEN-1, 20)); | 348 | SEPARATOR(i, DIST_CODE_LEN-1, 20)); |
| 356 | } | 349 | } |
| 357 | 350 | ||
| 358 | fprintf(header, "local const uch length_code[MAX_MATCH-MIN_MATCH+1]= {\n"); | 351 | fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n"); |
| 359 | for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) { | 352 | for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) { |
| 360 | fprintf(header, "%2u%s", length_code[i], | 353 | fprintf(header, "%2u%s", _length_code[i], |
| 361 | SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20)); | 354 | SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20)); |
| 362 | } | 355 | } |
| 363 | 356 | ||
| @@ -1045,7 +1038,7 @@ int _tr_tally (s, dist, lc) | |||
| 1045 | (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) && | 1038 | (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) && |
| 1046 | (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match"); | 1039 | (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match"); |
| 1047 | 1040 | ||
| 1048 | s->dyn_ltree[length_code[lc]+LITERALS+1].Freq++; | 1041 | s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++; |
| 1049 | s->dyn_dtree[d_code(dist)].Freq++; | 1042 | s->dyn_dtree[d_code(dist)].Freq++; |
| 1050 | } | 1043 | } |
| 1051 | 1044 | ||
| @@ -1094,7 +1087,7 @@ local void compress_block(s, ltree, dtree) | |||
| 1094 | Tracecv(isgraph(lc), (stderr," '%c' ", lc)); | 1087 | Tracecv(isgraph(lc), (stderr," '%c' ", lc)); |
| 1095 | } else { | 1088 | } else { |
| 1096 | /* Here, lc is the match length - MIN_MATCH */ | 1089 | /* Here, lc is the match length - MIN_MATCH */ |
| 1097 | code = length_code[lc]; | 1090 | code = _length_code[lc]; |
| 1098 | send_code(s, code+LITERALS+1, ltree); /* send the length code */ | 1091 | send_code(s, code+LITERALS+1, ltree); /* send the length code */ |
| 1099 | extra = extra_lbits[code]; | 1092 | extra = extra_lbits[code]; |
| 1100 | if (extra != 0) { | 1093 | if (extra != 0) { |
