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)
| 1237 | * match.S. The code will be functionally equivalent. |
| 1238 | */ |
| 1239 | local uInt longest_match(s, cur_match) |
| 1240 | deflate_state *s; |
| 1241 | IPos cur_match; /* current match */ |
| 1242 | { |
| 1243 | unsigned chain_length = s->max_chain_length;/* max hash chain length */ |
| 1244 | register Bytef *scan = s->window + s->strstart; /* current string */ |
| 1245 | register Bytef *match; /* matched string */ |
| 1246 | register int len; /* length of current match */ |
| 1247 | int best_len = (int)s->prev_length; /* best match length so far */ |
| 1248 | int nice_match = s->nice_match; /* stop if match long enough */ |
| 1249 | IPos limit = s->strstart > (IPos)MAX_DIST(s) ? |
| 1250 | s->strstart - (IPos)MAX_DIST(s) : NIL; |
| 1251 | /* Stop when cur_match becomes <= limit. To simplify the code, |
| 1252 | * we prevent matches with the string of window index 0. |
| 1253 | */ |
| 1254 | Posf *prev = s->prev; |
| 1255 | uInt wmask = s->w_mask; |
| 1256 | |
| 1257 | #ifdef UNALIGNED_OK |
| 1258 | /* Compare two bytes at a time. Note: this is not always beneficial. |
| 1259 | * Try with and without -DUNALIGNED_OK to check. |
| 1260 | */ |
| 1261 | register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1; |
| 1262 | register ush scan_start = *(ushf*)scan; |
| 1263 | register ush scan_end = *(ushf*)(scan+best_len-1); |
| 1264 | #else |
| 1265 | register Bytef *strend = s->window + s->strstart + MAX_MATCH; |
| 1266 | register Byte scan_end1 = scan[best_len-1]; |
| 1267 | register Byte scan_end = scan[best_len]; |
| 1268 | #endif |
| 1269 | |
| 1270 | /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. |
| 1271 | * It is easy to get rid of this optimization if necessary. |
| 1272 | */ |
| 1273 | Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); |
| 1274 | |
| 1275 | /* Do not waste too much time if we already have a good match: */ |
| 1276 | if (s->prev_length >= s->good_match) { |
| 1277 | chain_length >>= 2; |
| 1278 | } |
| 1279 | /* Do not look for matches beyond the end of the input. This is necessary |
| 1280 | * to make deflate deterministic. |
| 1281 | */ |
| 1282 | if ((uInt)nice_match > s->lookahead) nice_match = (int)s->lookahead; |
| 1283 | |
| 1284 | Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); |
| 1285 | |
| 1286 | do { |
| 1287 | Assert(cur_match < s->strstart, "no future"); |
| 1288 | match = s->window + cur_match; |
| 1289 | |
| 1290 | /* Skip to next match if the match length cannot increase |
| 1291 | * or if the match length is less than 2. Note that the checks below |
| 1292 | * for insufficient lookahead only occur occasionally for performance |
| 1293 | * reasons. Therefore uninitialized memory will be accessed, and |
| 1294 | * conditional jumps will be made that depend on those values. |
| 1295 | * However the length of the match is limited to the lookahead, so |
| 1296 | * the output of deflate is not affected by the uninitialized values. |
no outgoing calls
no test coverage detected