MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / fill_window

Function fill_window

extern/zlib/src/deflate.c:251–368  ·  view source on GitHub ↗

=========================================================================== * 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

Source from the content-addressed store, hash-verified

249 * option -- not supported here).
250 */
251local void fill_window(deflate_state *s) {
252 unsigned n;
253 unsigned more; /* Amount of free space at the end of the window. */
254 uInt wsize = s->w_size;
255
256 Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
257
258 do {
259 more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
260
261 /* Deal with !@#$% 64K limit: */
262 if (sizeof(int) <= 2) {
263 if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
264 more = wsize;
265
266 } else if (more == (unsigned)(-1)) {
267 /* Very unlikely, but possible on 16 bit machine if
268 * strstart == 0 && lookahead == 1 (input done a byte at time)
269 */
270 more--;
271 }
272 }
273
274 /* If the window is almost full and there is insufficient lookahead,
275 * move the upper half to the lower one to make room in the upper half.
276 */
277 if (s->strstart >= wsize + MAX_DIST(s)) {
278
279 zmemcpy(s->window, s->window + wsize, (unsigned)wsize - more);
280 s->match_start -= wsize;
281 s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
282 s->block_start -= (long) wsize;
283 if (s->insert > s->strstart)
284 s->insert = s->strstart;
285 slide_hash(s);
286 more += wsize;
287 }
288 if (s->strm->avail_in == 0) break;
289
290 /* If there was no sliding:
291 * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
292 * more == window_size - lookahead - strstart
293 * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)
294 * => more >= window_size - 2*WSIZE + 2
295 * In the BIG_MEM or MMAP case (not yet supported),
296 * window_size == input_size + MIN_LOOKAHEAD &&
297 * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.
298 * Otherwise, window_size == 2*WSIZE so more >= 2.
299 * If there was sliding, more >= WSIZE. So in all cases, more >= 2.
300 */
301 Assert(more >= 2, "more < 2");
302
303 n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
304 s->lookahead += n;
305
306 /* Initialize the hash value now that we have some input: */
307 if (s->lookahead + s->insert >= MIN_MATCH) {
308 uInt str = s->strstart - s->insert;

Callers 5

deflateSetDictionaryFunction · 0.85
deflate_fastFunction · 0.85
deflate_slowFunction · 0.85
deflate_rleFunction · 0.85
deflate_huffFunction · 0.85

Calls 4

zmemcpyFunction · 0.85
slide_hashFunction · 0.85
read_bufFunction · 0.85
zmemzeroFunction · 0.85

Tested by

no test coverage detected