diff options
author | Mark Adler <fork@madler.net> | 2022-10-01 17:04:06 -0700 |
---|---|---|
committer | Mark Adler <fork@madler.net> | 2022-10-05 15:17:52 -0700 |
commit | 84c6716a48743edfb71053ba07755e0cf7ba638d (patch) | |
tree | 5e02319722d8682bd51f7de01f38b21bb13756c8 /deflate.c | |
parent | 3e4aa45834c2e76c1f21f9c463c2f356f3bb512c (diff) | |
download | zlib-84c6716a48743edfb71053ba07755e0cf7ba638d.tar.gz zlib-84c6716a48743edfb71053ba07755e0cf7ba638d.tar.bz2 zlib-84c6716a48743edfb71053ba07755e0cf7ba638d.zip |
Minor formatting improvements.
No code changes.
Diffstat (limited to 'deflate.c')
-rw-r--r-- | deflate.c | 137 |
1 files changed, 71 insertions, 66 deletions
@@ -160,7 +160,7 @@ local const config configuration_table[10] = { | |||
160 | * characters, so that a running hash key can be computed from the previous | 160 | * characters, so that a running hash key can be computed from the previous |
161 | * key instead of complete recalculation each time. | 161 | * key instead of complete recalculation each time. |
162 | */ | 162 | */ |
163 | #define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask) | 163 | #define UPDATE_HASH(s,h,c) (h = (((h) << s->hash_shift) ^ (c)) & s->hash_mask) |
164 | 164 | ||
165 | 165 | ||
166 | /* =========================================================================== | 166 | /* =========================================================================== |
@@ -191,9 +191,9 @@ local const config configuration_table[10] = { | |||
191 | */ | 191 | */ |
192 | #define CLEAR_HASH(s) \ | 192 | #define CLEAR_HASH(s) \ |
193 | do { \ | 193 | do { \ |
194 | s->head[s->hash_size-1] = NIL; \ | 194 | s->head[s->hash_size - 1] = NIL; \ |
195 | zmemzero((Bytef *)s->head, \ | 195 | zmemzero((Bytef *)s->head, \ |
196 | (unsigned)(s->hash_size-1)*sizeof(*s->head)); \ | 196 | (unsigned)(s->hash_size - 1)*sizeof(*s->head)); \ |
197 | } while (0) | 197 | } while (0) |
198 | 198 | ||
199 | /* =========================================================================== | 199 | /* =========================================================================== |
@@ -314,7 +314,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, | |||
314 | s->hash_bits = (uInt)memLevel + 7; | 314 | s->hash_bits = (uInt)memLevel + 7; |
315 | s->hash_size = 1 << s->hash_bits; | 315 | s->hash_size = 1 << s->hash_bits; |
316 | s->hash_mask = s->hash_size - 1; | 316 | s->hash_mask = s->hash_size - 1; |
317 | s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH); | 317 | s->hash_shift = ((s->hash_bits + MIN_MATCH-1) / MIN_MATCH); |
318 | 318 | ||
319 | s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte)); | 319 | s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte)); |
320 | s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos)); | 320 | s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos)); |
@@ -340,11 +340,11 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, | |||
340 | * sym_buf value to read moves forward three bytes. From that symbol, up to | 340 | * sym_buf value to read moves forward three bytes. From that symbol, up to |
341 | * 31 bits are written to pending_buf. The closest the written pending_buf | 341 | * 31 bits are written to pending_buf. The closest the written pending_buf |
342 | * bits gets to the next sym_buf symbol to read is just before the last | 342 | * bits gets to the next sym_buf symbol to read is just before the last |
343 | * code is written. At that time, 31*(n-2) bits have been written, just | 343 | * code is written. At that time, 31*(n - 2) bits have been written, just |
344 | * after 24*(n-2) bits have been consumed from sym_buf. sym_buf starts at | 344 | * after 24*(n - 2) bits have been consumed from sym_buf. sym_buf starts at |
345 | * 8*n bits into pending_buf. (Note that the symbol buffer fills when n-1 | 345 | * 8*n bits into pending_buf. (Note that the symbol buffer fills when n - 1 |
346 | * symbols are written.) The closest the writing gets to what is unread is | 346 | * symbols are written.) The closest the writing gets to what is unread is |
347 | * then n+14 bits. Here n is lit_bufsize, which is 16384 by default, and | 347 | * then n + 14 bits. Here n is lit_bufsize, which is 16384 by default, and |
348 | * can range from 128 to 32768. | 348 | * can range from 128 to 32768. |
349 | * | 349 | * |
350 | * Therefore, at a minimum, there are 142 bits of space between what is | 350 | * Therefore, at a minimum, there are 142 bits of space between what is |
@@ -390,7 +390,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, | |||
390 | /* ========================================================================= | 390 | /* ========================================================================= |
391 | * Check for a valid deflate stream state. Return 0 if ok, 1 if not. | 391 | * Check for a valid deflate stream state. Return 0 if ok, 1 if not. |
392 | */ | 392 | */ |
393 | local int deflateStateCheck (strm) | 393 | local int deflateStateCheck(strm) |
394 | z_streamp strm; | 394 | z_streamp strm; |
395 | { | 395 | { |
396 | deflate_state *s; | 396 | deflate_state *s; |
@@ -413,7 +413,7 @@ local int deflateStateCheck (strm) | |||
413 | } | 413 | } |
414 | 414 | ||
415 | /* ========================================================================= */ | 415 | /* ========================================================================= */ |
416 | int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength) | 416 | int ZEXPORT deflateSetDictionary(strm, dictionary, dictLength) |
417 | z_streamp strm; | 417 | z_streamp strm; |
418 | const Bytef *dictionary; | 418 | const Bytef *dictionary; |
419 | uInt dictLength; | 419 | uInt dictLength; |
@@ -482,7 +482,7 @@ int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength) | |||
482 | } | 482 | } |
483 | 483 | ||
484 | /* ========================================================================= */ | 484 | /* ========================================================================= */ |
485 | int ZEXPORT deflateGetDictionary (strm, dictionary, dictLength) | 485 | int ZEXPORT deflateGetDictionary(strm, dictionary, dictLength) |
486 | z_streamp strm; | 486 | z_streamp strm; |
487 | Bytef *dictionary; | 487 | Bytef *dictionary; |
488 | uInt *dictLength; | 488 | uInt *dictLength; |
@@ -504,7 +504,7 @@ int ZEXPORT deflateGetDictionary (strm, dictionary, dictLength) | |||
504 | } | 504 | } |
505 | 505 | ||
506 | /* ========================================================================= */ | 506 | /* ========================================================================= */ |
507 | int ZEXPORT deflateResetKeep (strm) | 507 | int ZEXPORT deflateResetKeep(strm) |
508 | z_streamp strm; | 508 | z_streamp strm; |
509 | { | 509 | { |
510 | deflate_state *s; | 510 | deflate_state *s; |
@@ -542,7 +542,7 @@ int ZEXPORT deflateResetKeep (strm) | |||
542 | } | 542 | } |
543 | 543 | ||
544 | /* ========================================================================= */ | 544 | /* ========================================================================= */ |
545 | int ZEXPORT deflateReset (strm) | 545 | int ZEXPORT deflateReset(strm) |
546 | z_streamp strm; | 546 | z_streamp strm; |
547 | { | 547 | { |
548 | int ret; | 548 | int ret; |
@@ -554,7 +554,7 @@ int ZEXPORT deflateReset (strm) | |||
554 | } | 554 | } |
555 | 555 | ||
556 | /* ========================================================================= */ | 556 | /* ========================================================================= */ |
557 | int ZEXPORT deflateSetHeader (strm, head) | 557 | int ZEXPORT deflateSetHeader(strm, head) |
558 | z_streamp strm; | 558 | z_streamp strm; |
559 | gz_headerp head; | 559 | gz_headerp head; |
560 | { | 560 | { |
@@ -565,7 +565,7 @@ int ZEXPORT deflateSetHeader (strm, head) | |||
565 | } | 565 | } |
566 | 566 | ||
567 | /* ========================================================================= */ | 567 | /* ========================================================================= */ |
568 | int ZEXPORT deflatePending (strm, pending, bits) | 568 | int ZEXPORT deflatePending(strm, pending, bits) |
569 | unsigned *pending; | 569 | unsigned *pending; |
570 | int *bits; | 570 | int *bits; |
571 | z_streamp strm; | 571 | z_streamp strm; |
@@ -579,7 +579,7 @@ int ZEXPORT deflatePending (strm, pending, bits) | |||
579 | } | 579 | } |
580 | 580 | ||
581 | /* ========================================================================= */ | 581 | /* ========================================================================= */ |
582 | int ZEXPORT deflatePrime (strm, bits, value) | 582 | int ZEXPORT deflatePrime(strm, bits, value) |
583 | z_streamp strm; | 583 | z_streamp strm; |
584 | int bits; | 584 | int bits; |
585 | int value; | 585 | int value; |
@@ -769,7 +769,7 @@ uLong ZEXPORT deflateBound(strm, sourceLen) | |||
769 | * IN assertion: the stream state is correct and there is enough room in | 769 | * IN assertion: the stream state is correct and there is enough room in |
770 | * pending_buf. | 770 | * pending_buf. |
771 | */ | 771 | */ |
772 | local void putShortMSB (s, b) | 772 | local void putShortMSB(s, b) |
773 | deflate_state *s; | 773 | deflate_state *s; |
774 | uInt b; | 774 | uInt b; |
775 | { | 775 | { |
@@ -816,7 +816,7 @@ local void flush_pending(strm) | |||
816 | } while (0) | 816 | } while (0) |
817 | 817 | ||
818 | /* ========================================================================= */ | 818 | /* ========================================================================= */ |
819 | int ZEXPORT deflate (strm, flush) | 819 | int ZEXPORT deflate(strm, flush) |
820 | z_streamp strm; | 820 | z_streamp strm; |
821 | int flush; | 821 | int flush; |
822 | { | 822 | { |
@@ -871,7 +871,7 @@ int ZEXPORT deflate (strm, flush) | |||
871 | s->status = BUSY_STATE; | 871 | s->status = BUSY_STATE; |
872 | if (s->status == INIT_STATE) { | 872 | if (s->status == INIT_STATE) { |
873 | /* zlib header */ | 873 | /* zlib header */ |
874 | uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8; | 874 | uInt header = (Z_DEFLATED + ((s->w_bits - 8) << 4)) << 8; |
875 | uInt level_flags; | 875 | uInt level_flags; |
876 | 876 | ||
877 | if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2) | 877 | if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2) |
@@ -1131,7 +1131,7 @@ int ZEXPORT deflate (strm, flush) | |||
1131 | } | 1131 | } |
1132 | 1132 | ||
1133 | /* ========================================================================= */ | 1133 | /* ========================================================================= */ |
1134 | int ZEXPORT deflateEnd (strm) | 1134 | int ZEXPORT deflateEnd(strm) |
1135 | z_streamp strm; | 1135 | z_streamp strm; |
1136 | { | 1136 | { |
1137 | int status; | 1137 | int status; |
@@ -1157,7 +1157,7 @@ int ZEXPORT deflateEnd (strm) | |||
1157 | * To simplify the source, this is not supported for 16-bit MSDOS (which | 1157 | * To simplify the source, this is not supported for 16-bit MSDOS (which |
1158 | * doesn't have enough memory anyway to duplicate compression states). | 1158 | * doesn't have enough memory anyway to duplicate compression states). |
1159 | */ | 1159 | */ |
1160 | int ZEXPORT deflateCopy (dest, source) | 1160 | int ZEXPORT deflateCopy(dest, source) |
1161 | z_streamp dest; | 1161 | z_streamp dest; |
1162 | z_streamp source; | 1162 | z_streamp source; |
1163 | { | 1163 | { |
@@ -1246,7 +1246,7 @@ local unsigned read_buf(strm, buf, size) | |||
1246 | /* =========================================================================== | 1246 | /* =========================================================================== |
1247 | * Initialize the "longest match" routines for a new zlib stream | 1247 | * Initialize the "longest match" routines for a new zlib stream |
1248 | */ | 1248 | */ |
1249 | local void lm_init (s) | 1249 | local void lm_init(s) |
1250 | deflate_state *s; | 1250 | deflate_state *s; |
1251 | { | 1251 | { |
1252 | s->window_size = (ulg)2L*s->w_size; | 1252 | s->window_size = (ulg)2L*s->w_size; |
@@ -1312,10 +1312,10 @@ local uInt longest_match(s, cur_match) | |||
1312 | */ | 1312 | */ |
1313 | register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1; | 1313 | register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1; |
1314 | register ush scan_start = *(ushf*)scan; | 1314 | register ush scan_start = *(ushf*)scan; |
1315 | register ush scan_end = *(ushf*)(scan+best_len-1); | 1315 | register ush scan_end = *(ushf*)(scan + best_len - 1); |
1316 | #else | 1316 | #else |
1317 | register Bytef *strend = s->window + s->strstart + MAX_MATCH; | 1317 | register Bytef *strend = s->window + s->strstart + MAX_MATCH; |
1318 | register Byte scan_end1 = scan[best_len-1]; | 1318 | register Byte scan_end1 = scan[best_len - 1]; |
1319 | register Byte scan_end = scan[best_len]; | 1319 | register Byte scan_end = scan[best_len]; |
1320 | #endif | 1320 | #endif |
1321 | 1321 | ||
@@ -1333,7 +1333,8 @@ local uInt longest_match(s, cur_match) | |||
1333 | */ | 1333 | */ |
1334 | if ((uInt)nice_match > s->lookahead) nice_match = (int)s->lookahead; | 1334 | if ((uInt)nice_match > s->lookahead) nice_match = (int)s->lookahead; |
1335 | 1335 | ||
1336 | Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); | 1336 | Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD, |
1337 | "need lookahead"); | ||
1337 | 1338 | ||
1338 | do { | 1339 | do { |
1339 | Assert(cur_match < s->strstart, "no future"); | 1340 | Assert(cur_match < s->strstart, "no future"); |
@@ -1351,43 +1352,44 @@ local uInt longest_match(s, cur_match) | |||
1351 | /* This code assumes sizeof(unsigned short) == 2. Do not use | 1352 | /* This code assumes sizeof(unsigned short) == 2. Do not use |
1352 | * UNALIGNED_OK if your compiler uses a different size. | 1353 | * UNALIGNED_OK if your compiler uses a different size. |
1353 | */ | 1354 | */ |
1354 | if (*(ushf*)(match+best_len-1) != scan_end || | 1355 | if (*(ushf*)(match + best_len - 1) != scan_end || |
1355 | *(ushf*)match != scan_start) continue; | 1356 | *(ushf*)match != scan_start) continue; |
1356 | 1357 | ||
1357 | /* It is not necessary to compare scan[2] and match[2] since they are | 1358 | /* It is not necessary to compare scan[2] and match[2] since they are |
1358 | * always equal when the other bytes match, given that the hash keys | 1359 | * always equal when the other bytes match, given that the hash keys |
1359 | * are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at | 1360 | * are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at |
1360 | * strstart+3, +5, ... up to strstart+257. We check for insufficient | 1361 | * strstart + 3, + 5, up to strstart + 257. We check for insufficient |
1361 | * lookahead only every 4th comparison; the 128th check will be made | 1362 | * lookahead only every 4th comparison; the 128th check will be made |
1362 | * at strstart+257. If MAX_MATCH-2 is not a multiple of 8, it is | 1363 | * at strstart + 257. If MAX_MATCH-2 is not a multiple of 8, it is |
1363 | * necessary to put more guard bytes at the end of the window, or | 1364 | * necessary to put more guard bytes at the end of the window, or |
1364 | * to check more often for insufficient lookahead. | 1365 | * to check more often for insufficient lookahead. |
1365 | */ | 1366 | */ |
1366 | Assert(scan[2] == match[2], "scan[2]?"); | 1367 | Assert(scan[2] == match[2], "scan[2]?"); |
1367 | scan++, match++; | 1368 | scan++, match++; |
1368 | do { | 1369 | do { |
1369 | } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) && | 1370 | } while (*(ushf*)(scan += 2) == *(ushf*)(match += 2) && |
1370 | *(ushf*)(scan+=2) == *(ushf*)(match+=2) && | 1371 | *(ushf*)(scan += 2) == *(ushf*)(match += 2) && |
1371 | *(ushf*)(scan+=2) == *(ushf*)(match+=2) && | 1372 | *(ushf*)(scan += 2) == *(ushf*)(match += 2) && |
1372 | *(ushf*)(scan+=2) == *(ushf*)(match+=2) && | 1373 | *(ushf*)(scan += 2) == *(ushf*)(match += 2) && |
1373 | scan < strend); | 1374 | scan < strend); |
1374 | /* The funny "do {}" generates better code on most compilers */ | 1375 | /* The funny "do {}" generates better code on most compilers */ |
1375 | 1376 | ||
1376 | /* Here, scan <= window+strstart+257 */ | 1377 | /* Here, scan <= window + strstart + 257 */ |
1377 | Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); | 1378 | Assert(scan <= s->window + (unsigned)(s->window_size - 1), |
1379 | "wild scan"); | ||
1378 | if (*scan == *match) scan++; | 1380 | if (*scan == *match) scan++; |
1379 | 1381 | ||
1380 | len = (MAX_MATCH - 1) - (int)(strend-scan); | 1382 | len = (MAX_MATCH - 1) - (int)(strend - scan); |
1381 | scan = strend - (MAX_MATCH-1); | 1383 | scan = strend - (MAX_MATCH-1); |
1382 | 1384 | ||
1383 | #else /* UNALIGNED_OK */ | 1385 | #else /* UNALIGNED_OK */ |
1384 | 1386 | ||
1385 | if (match[best_len] != scan_end || | 1387 | if (match[best_len] != scan_end || |
1386 | match[best_len-1] != scan_end1 || | 1388 | match[best_len - 1] != scan_end1 || |
1387 | *match != *scan || | 1389 | *match != *scan || |
1388 | *++match != scan[1]) continue; | 1390 | *++match != scan[1]) continue; |
1389 | 1391 | ||
1390 | /* The check at best_len-1 can be removed because it will be made | 1392 | /* The check at best_len - 1 can be removed because it will be made |
1391 | * again later. (This heuristic is not always a win.) | 1393 | * again later. (This heuristic is not always a win.) |
1392 | * It is not necessary to compare scan[2] and match[2] since they | 1394 | * It is not necessary to compare scan[2] and match[2] since they |
1393 | * are always equal when the other bytes match, given that | 1395 | * are always equal when the other bytes match, given that |
@@ -1397,7 +1399,7 @@ local uInt longest_match(s, cur_match) | |||
1397 | Assert(*scan == *match, "match[2]?"); | 1399 | Assert(*scan == *match, "match[2]?"); |
1398 | 1400 | ||
1399 | /* We check for insufficient lookahead only every 8th comparison; | 1401 | /* We check for insufficient lookahead only every 8th comparison; |
1400 | * the 256th check will be made at strstart+258. | 1402 | * the 256th check will be made at strstart + 258. |
1401 | */ | 1403 | */ |
1402 | do { | 1404 | do { |
1403 | } while (*++scan == *++match && *++scan == *++match && | 1405 | } while (*++scan == *++match && *++scan == *++match && |
@@ -1406,7 +1408,8 @@ local uInt longest_match(s, cur_match) | |||
1406 | *++scan == *++match && *++scan == *++match && | 1408 | *++scan == *++match && *++scan == *++match && |
1407 | scan < strend); | 1409 | scan < strend); |
1408 | 1410 | ||
1409 | Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); | 1411 | Assert(scan <= s->window + (unsigned)(s->window_size - 1), |
1412 | "wild scan"); | ||
1410 | 1413 | ||
1411 | len = MAX_MATCH - (int)(strend - scan); | 1414 | len = MAX_MATCH - (int)(strend - scan); |
1412 | scan = strend - MAX_MATCH; | 1415 | scan = strend - MAX_MATCH; |
@@ -1418,9 +1421,9 @@ local uInt longest_match(s, cur_match) | |||
1418 | best_len = len; | 1421 | best_len = len; |
1419 | if (len >= nice_match) break; | 1422 | if (len >= nice_match) break; |
1420 | #ifdef UNALIGNED_OK | 1423 | #ifdef UNALIGNED_OK |
1421 | scan_end = *(ushf*)(scan+best_len-1); | 1424 | scan_end = *(ushf*)(scan + best_len - 1); |
1422 | #else | 1425 | #else |
1423 | scan_end1 = scan[best_len-1]; | 1426 | scan_end1 = scan[best_len - 1]; |
1424 | scan_end = scan[best_len]; | 1427 | scan_end = scan[best_len]; |
1425 | #endif | 1428 | #endif |
1426 | } | 1429 | } |
@@ -1451,7 +1454,8 @@ local uInt longest_match(s, cur_match) | |||
1451 | */ | 1454 | */ |
1452 | Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); | 1455 | Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); |
1453 | 1456 | ||
1454 | Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); | 1457 | Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD, |
1458 | "need lookahead"); | ||
1455 | 1459 | ||
1456 | Assert(cur_match < s->strstart, "no future"); | 1460 | Assert(cur_match < s->strstart, "no future"); |
1457 | 1461 | ||
@@ -1461,7 +1465,7 @@ local uInt longest_match(s, cur_match) | |||
1461 | */ | 1465 | */ |
1462 | if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1; | 1466 | if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1; |
1463 | 1467 | ||
1464 | /* The check at best_len-1 can be removed because it will be made | 1468 | /* The check at best_len - 1 can be removed because it will be made |
1465 | * again later. (This heuristic is not always a win.) | 1469 | * again later. (This heuristic is not always a win.) |
1466 | * It is not necessary to compare scan[2] and match[2] since they | 1470 | * It is not necessary to compare scan[2] and match[2] since they |
1467 | * are always equal when the other bytes match, given that | 1471 | * are always equal when the other bytes match, given that |
@@ -1471,7 +1475,7 @@ local uInt longest_match(s, cur_match) | |||
1471 | Assert(*scan == *match, "match[2]?"); | 1475 | Assert(*scan == *match, "match[2]?"); |
1472 | 1476 | ||
1473 | /* We check for insufficient lookahead only every 8th comparison; | 1477 | /* We check for insufficient lookahead only every 8th comparison; |
1474 | * the 256th check will be made at strstart+258. | 1478 | * the 256th check will be made at strstart + 258. |
1475 | */ | 1479 | */ |
1476 | do { | 1480 | do { |
1477 | } while (*++scan == *++match && *++scan == *++match && | 1481 | } while (*++scan == *++match && *++scan == *++match && |
@@ -1480,7 +1484,7 @@ local uInt longest_match(s, cur_match) | |||
1480 | *++scan == *++match && *++scan == *++match && | 1484 | *++scan == *++match && *++scan == *++match && |
1481 | scan < strend); | 1485 | scan < strend); |
1482 | 1486 | ||
1483 | Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); | 1487 | Assert(scan <= s->window + (unsigned)(s->window_size - 1), "wild scan"); |
1484 | 1488 | ||
1485 | len = MAX_MATCH - (int)(strend - scan); | 1489 | len = MAX_MATCH - (int)(strend - scan); |
1486 | 1490 | ||
@@ -1516,7 +1520,7 @@ local void check_match(s, start, match, length) | |||
1516 | z_error("invalid match"); | 1520 | z_error("invalid match"); |
1517 | } | 1521 | } |
1518 | if (z_verbose > 1) { | 1522 | if (z_verbose > 1) { |
1519 | fprintf(stderr,"\\[%d,%d]", start-match, length); | 1523 | fprintf(stderr,"\\[%d,%d]", start - match, length); |
1520 | do { putc(s->window[start++], stderr); } while (--length != 0); | 1524 | do { putc(s->window[start++], stderr); } while (--length != 0); |
1521 | } | 1525 | } |
1522 | } | 1526 | } |
@@ -1562,9 +1566,9 @@ local void fill_window(s) | |||
1562 | /* If the window is almost full and there is insufficient lookahead, | 1566 | /* If the window is almost full and there is insufficient lookahead, |
1563 | * move the upper half to the lower one to make room in the upper half. | 1567 | * move the upper half to the lower one to make room in the upper half. |
1564 | */ | 1568 | */ |
1565 | if (s->strstart >= wsize+MAX_DIST(s)) { | 1569 | if (s->strstart >= wsize + MAX_DIST(s)) { |
1566 | 1570 | ||
1567 | zmemcpy(s->window, s->window+wsize, (unsigned)wsize - more); | 1571 | zmemcpy(s->window, s->window + wsize, (unsigned)wsize - more); |
1568 | s->match_start -= wsize; | 1572 | s->match_start -= wsize; |
1569 | s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ | 1573 | s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ |
1570 | s->block_start -= (long) wsize; | 1574 | s->block_start -= (long) wsize; |
@@ -1905,7 +1909,7 @@ local block_state deflate_fast(s, flush) | |||
1905 | if (s->lookahead == 0) break; /* flush the current block */ | 1909 | if (s->lookahead == 0) break; /* flush the current block */ |
1906 | } | 1910 | } |
1907 | 1911 | ||
1908 | /* Insert the string window[strstart .. strstart+2] in the | 1912 | /* Insert the string window[strstart .. strstart + 2] in the |
1909 | * dictionary, and set hash_head to the head of the hash chain: | 1913 | * dictionary, and set hash_head to the head of the hash chain: |
1910 | */ | 1914 | */ |
1911 | hash_head = NIL; | 1915 | hash_head = NIL; |
@@ -1953,7 +1957,7 @@ local block_state deflate_fast(s, flush) | |||
1953 | s->strstart += s->match_length; | 1957 | s->strstart += s->match_length; |
1954 | s->match_length = 0; | 1958 | s->match_length = 0; |
1955 | s->ins_h = s->window[s->strstart]; | 1959 | s->ins_h = s->window[s->strstart]; |
1956 | UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]); | 1960 | UPDATE_HASH(s, s->ins_h, s->window[s->strstart + 1]); |
1957 | #if MIN_MATCH != 3 | 1961 | #if MIN_MATCH != 3 |
1958 | Call UPDATE_HASH() MIN_MATCH-3 more times | 1962 | Call UPDATE_HASH() MIN_MATCH-3 more times |
1959 | #endif | 1963 | #endif |
@@ -1964,7 +1968,7 @@ local block_state deflate_fast(s, flush) | |||
1964 | } else { | 1968 | } else { |
1965 | /* No match, output a literal byte */ | 1969 | /* No match, output a literal byte */ |
1966 | Tracevv((stderr,"%c", s->window[s->strstart])); | 1970 | Tracevv((stderr,"%c", s->window[s->strstart])); |
1967 | _tr_tally_lit (s, s->window[s->strstart], bflush); | 1971 | _tr_tally_lit(s, s->window[s->strstart], bflush); |
1968 | s->lookahead--; | 1972 | s->lookahead--; |
1969 | s->strstart++; | 1973 | s->strstart++; |
1970 | } | 1974 | } |
@@ -2008,7 +2012,7 @@ local block_state deflate_slow(s, flush) | |||
2008 | if (s->lookahead == 0) break; /* flush the current block */ | 2012 | if (s->lookahead == 0) break; /* flush the current block */ |
2009 | } | 2013 | } |
2010 | 2014 | ||
2011 | /* Insert the string window[strstart .. strstart+2] in the | 2015 | /* Insert the string window[strstart .. strstart + 2] in the |
2012 | * dictionary, and set hash_head to the head of the hash chain: | 2016 | * dictionary, and set hash_head to the head of the hash chain: |
2013 | */ | 2017 | */ |
2014 | hash_head = NIL; | 2018 | hash_head = NIL; |
@@ -2050,17 +2054,17 @@ local block_state deflate_slow(s, flush) | |||
2050 | uInt max_insert = s->strstart + s->lookahead - MIN_MATCH; | 2054 | uInt max_insert = s->strstart + s->lookahead - MIN_MATCH; |
2051 | /* Do not insert strings in hash table beyond this. */ | 2055 | /* Do not insert strings in hash table beyond this. */ |
2052 | 2056 | ||
2053 | check_match(s, s->strstart-1, s->prev_match, s->prev_length); | 2057 | check_match(s, s->strstart - 1, s->prev_match, s->prev_length); |
2054 | 2058 | ||
2055 | _tr_tally_dist(s, s->strstart -1 - s->prev_match, | 2059 | _tr_tally_dist(s, s->strstart - 1 - s->prev_match, |
2056 | s->prev_length - MIN_MATCH, bflush); | 2060 | s->prev_length - MIN_MATCH, bflush); |
2057 | 2061 | ||
2058 | /* Insert in hash table all strings up to the end of the match. | 2062 | /* Insert in hash table all strings up to the end of the match. |
2059 | * strstart-1 and strstart are already inserted. If there is not | 2063 | * strstart - 1 and strstart are already inserted. If there is not |
2060 | * enough lookahead, the last two strings are not inserted in | 2064 | * enough lookahead, the last two strings are not inserted in |
2061 | * the hash table. | 2065 | * the hash table. |
2062 | */ | 2066 | */ |
2063 | s->lookahead -= s->prev_length-1; | 2067 | s->lookahead -= s->prev_length - 1; |
2064 | s->prev_length -= 2; | 2068 | s->prev_length -= 2; |
2065 | do { | 2069 | do { |
2066 | if (++s->strstart <= max_insert) { | 2070 | if (++s->strstart <= max_insert) { |
@@ -2078,8 +2082,8 @@ local block_state deflate_slow(s, flush) | |||
2078 | * single literal. If there was a match but the current match | 2082 | * single literal. If there was a match but the current match |
2079 | * is longer, truncate the previous match to a single literal. | 2083 | * is longer, truncate the previous match to a single literal. |
2080 | */ | 2084 | */ |
2081 | Tracevv((stderr,"%c", s->window[s->strstart-1])); | 2085 | Tracevv((stderr,"%c", s->window[s->strstart - 1])); |
2082 | _tr_tally_lit(s, s->window[s->strstart-1], bflush); | 2086 | _tr_tally_lit(s, s->window[s->strstart - 1], bflush); |
2083 | if (bflush) { | 2087 | if (bflush) { |
2084 | FLUSH_BLOCK_ONLY(s, 0); | 2088 | FLUSH_BLOCK_ONLY(s, 0); |
2085 | } | 2089 | } |
@@ -2097,8 +2101,8 @@ local block_state deflate_slow(s, flush) | |||
2097 | } | 2101 | } |
2098 | Assert (flush != Z_NO_FLUSH, "no flush?"); | 2102 | Assert (flush != Z_NO_FLUSH, "no flush?"); |
2099 | if (s->match_available) { | 2103 | if (s->match_available) { |
2100 | Tracevv((stderr,"%c", s->window[s->strstart-1])); | 2104 | Tracevv((stderr,"%c", s->window[s->strstart - 1])); |
2101 | _tr_tally_lit(s, s->window[s->strstart-1], bflush); | 2105 | _tr_tally_lit(s, s->window[s->strstart - 1], bflush); |
2102 | s->match_available = 0; | 2106 | s->match_available = 0; |
2103 | } | 2107 | } |
2104 | s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1; | 2108 | s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1; |
@@ -2155,7 +2159,8 @@ local block_state deflate_rle(s, flush) | |||
2155 | if (s->match_length > s->lookahead) | 2159 | if (s->match_length > s->lookahead) |
2156 | s->match_length = s->lookahead; | 2160 | s->match_length = s->lookahead; |
2157 | } | 2161 | } |
2158 | Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan"); | 2162 | Assert(scan <= s->window + (uInt)(s->window_size - 1), |
2163 | "wild scan"); | ||
2159 | } | 2164 | } |
2160 | 2165 | ||
2161 | /* Emit match if have run of MIN_MATCH or longer, else emit literal */ | 2166 | /* Emit match if have run of MIN_MATCH or longer, else emit literal */ |
@@ -2170,7 +2175,7 @@ local block_state deflate_rle(s, flush) | |||
2170 | } else { | 2175 | } else { |
2171 | /* No match, output a literal byte */ | 2176 | /* No match, output a literal byte */ |
2172 | Tracevv((stderr,"%c", s->window[s->strstart])); | 2177 | Tracevv((stderr,"%c", s->window[s->strstart])); |
2173 | _tr_tally_lit (s, s->window[s->strstart], bflush); | 2178 | _tr_tally_lit(s, s->window[s->strstart], bflush); |
2174 | s->lookahead--; | 2179 | s->lookahead--; |
2175 | s->strstart++; | 2180 | s->strstart++; |
2176 | } | 2181 | } |
@@ -2210,7 +2215,7 @@ local block_state deflate_huff(s, flush) | |||
2210 | /* Output a literal byte */ | 2215 | /* Output a literal byte */ |
2211 | s->match_length = 0; | 2216 | s->match_length = 0; |
2212 | Tracevv((stderr,"%c", s->window[s->strstart])); | 2217 | Tracevv((stderr,"%c", s->window[s->strstart])); |
2213 | _tr_tally_lit (s, s->window[s->strstart], bflush); | 2218 | _tr_tally_lit(s, s->window[s->strstart], bflush); |
2214 | s->lookahead--; | 2219 | s->lookahead--; |
2215 | s->strstart++; | 2220 | s->strstart++; |
2216 | if (bflush) FLUSH_BLOCK(s, 0); | 2221 | if (bflush) FLUSH_BLOCK(s, 0); |