For 80x86 and 680x0, an optimized version will be provided in match.asm or * match.S. The code will be functionally equivalent. */
(s, cur_match)
| 1025 | * match.S. The code will be functionally equivalent. |
| 1026 | */ |
| 1027 | local uInt longest_match(s, cur_match) |
| 1028 | deflate_state *s; |
| 1029 | IPos cur_match; /* current match */ |
| 1030 | { |
| 1031 | unsigned chain_length = s->max_chain_length;/* max hash chain length */ |
| 1032 | register Bytef *scan = s->window + s->strstart; /* current string */ |
| 1033 | register Bytef *match; /* matched string */ |
| 1034 | register int len; /* length of current match */ |
| 1035 | int best_len = s->prev_length; /* best match length so far */ |
| 1036 | int nice_match = s->nice_match; /* stop if match long enough */ |
| 1037 | IPos limit = s->strstart > (IPos)MAX_DIST(s) ? |
| 1038 | s->strstart - (IPos)MAX_DIST(s) : NIL; |
| 1039 | /* Stop when cur_match becomes <= limit. To simplify the code, |
| 1040 | * we prevent matches with the string of window index 0. |
| 1041 | */ |
| 1042 | Posf *prev = s->prev; |
| 1043 | uInt wmask = s->w_mask; |
| 1044 | |
| 1045 | #ifdef UNALIGNED_OK |
| 1046 | /* Compare two bytes at a time. Note: this is not always beneficial. |
| 1047 | * Try with and without -DUNALIGNED_OK to check. |
| 1048 | */ |
| 1049 | register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1; |
| 1050 | register ush scan_start = *(ushf*)scan; |
| 1051 | register ush scan_end = *(ushf*)(scan+best_len-1); |
| 1052 | #else |
| 1053 | register Bytef *strend = s->window + s->strstart + MAX_MATCH; |
| 1054 | register Byte scan_end1 = scan[best_len-1]; |
| 1055 | register Byte scan_end = scan[best_len]; |
| 1056 | #endif |
| 1057 | |
| 1058 | /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. |
| 1059 | * It is easy to get rid of this optimization if necessary. |
| 1060 | */ |
| 1061 | Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); |
| 1062 | |
| 1063 | /* Do not waste too much time if we already have a good match: */ |
| 1064 | if (s->prev_length >= s->good_match) { |
| 1065 | chain_length >>= 2; |
| 1066 | } |
| 1067 | /* Do not look for matches beyond the end of the input. This is necessary |
| 1068 | * to make deflate deterministic. |
| 1069 | */ |
| 1070 | if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; |
| 1071 | |
| 1072 | Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); |
| 1073 | |
| 1074 | do { |
| 1075 | Assert(cur_match < s->strstart, "no future"); |
| 1076 | match = s->window + cur_match; |
| 1077 | |
| 1078 | /* Skip to next match if the match length cannot increase |
| 1079 | * or if the match length is less than 2. Note that the checks below |
| 1080 | * for insufficient lookahead only occur occasionally for performance |
| 1081 | * reasons. Therefore uninitialized memory will be accessed, and |
| 1082 | * conditional jumps will be made that depend on those values. |
| 1083 | * However the length of the match is limited to the lookahead, so |
| 1084 | * the output of deflate is not affected by the uninitialized values. |
no outgoing calls
no test coverage detected