=========================================================================== * Fill the window when the lookahead becomes insufficient. * Updates strstart and lookahead. * * IN assertion: lookahead < MIN_LOOKAHEAD * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD * At least one byte has been read, or avail_in == 0; reads are * performed for at least two bytes (required for the zi
(s)
| 1264 | * option -- not supported here). |
| 1265 | */ |
| 1266 | local void fill_window(s) |
| 1267 | deflate_state *s; |
| 1268 | { |
| 1269 | register unsigned n, m; |
| 1270 | register Posf *p; |
| 1271 | unsigned more; /* Amount of free space at the end of the window. */ |
| 1272 | uInt wsize = s->w_size; |
| 1273 | |
| 1274 | do { |
| 1275 | more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart); |
| 1276 | |
| 1277 | /* Deal with !@#$% 64K limit: */ |
| 1278 | if (sizeof(int) <= 2) { |
| 1279 | if (more == 0 && s->strstart == 0 && s->lookahead == 0) { |
| 1280 | more = wsize; |
| 1281 | |
| 1282 | } else if (more == (unsigned)(-1)) { |
| 1283 | /* Very unlikely, but possible on 16 bit machine if |
| 1284 | * strstart == 0 && lookahead == 1 (input done a byte at time) |
| 1285 | */ |
| 1286 | more--; |
| 1287 | } |
| 1288 | } |
| 1289 | |
| 1290 | /* If the window is almost full and there is insufficient lookahead, |
| 1291 | * move the upper half to the lower one to make room in the upper half. |
| 1292 | */ |
| 1293 | if (s->strstart >= wsize+MAX_DIST(s)) { |
| 1294 | |
| 1295 | zmemcpy(s->window, s->window+wsize, (unsigned)wsize); |
| 1296 | s->match_start -= wsize; |
| 1297 | s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ |
| 1298 | s->block_start -= (long) wsize; |
| 1299 | |
| 1300 | /* Slide the hash table (could be avoided with 32 bit values |
| 1301 | at the expense of memory usage). We slide even when level == 0 |
| 1302 | to keep the hash table consistent if we switch back to level > 0 |
| 1303 | later. (Using level 0 permanently is not an optimal usage of |
| 1304 | zlib, so we don't care about this pathological case.) |
| 1305 | */ |
| 1306 | /* %%% avoid this when Z_RLE */ |
| 1307 | n = s->hash_size; |
| 1308 | p = &s->head[n]; |
| 1309 | do { |
| 1310 | m = *--p; |
| 1311 | *p = (Pos)(m >= wsize ? m-wsize : NIL); |
| 1312 | } while (--n); |
| 1313 | |
| 1314 | n = wsize; |
| 1315 | #ifndef FASTEST |
| 1316 | p = &s->prev[n]; |
| 1317 | do { |
| 1318 | m = *--p; |
| 1319 | *p = (Pos)(m >= wsize ? m-wsize : NIL); |
| 1320 | /* If n is not on any hash chain, prev[n] is garbage but |
| 1321 | * its value will never be used. |
| 1322 | */ |
| 1323 | } while (--n); |
no test coverage detected