MCPcopy Index your code
hub / github.com/RsyncProject/rsync / fill_window

Function fill_window

zlib/deflate.c:1375–1516  ·  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

1373 * option -- not supported here).
1374 */
1375local void fill_window(deflate_state *s)
1376{
1377 register unsigned n, m;
1378 register Posf *p;
1379 unsigned more; /* Amount of free space at the end of the window. */
1380 uInt wsize = s->w_size;
1381
1382 Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
1383
1384 do {
1385 more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
1386
1387 /* Deal with !@#$% 64K limit: */
1388 if (sizeof(int) <= 2) {
1389 if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
1390 more = wsize;
1391
1392 } else if (more == (unsigned)(-1)) {
1393 /* Very unlikely, but possible on 16 bit machine if
1394 * strstart == 0 && lookahead == 1 (input done a byte at time)
1395 */
1396 more--;
1397 }
1398 }
1399
1400 /* If the window is almost full and there is insufficient lookahead,
1401 * move the upper half to the lower one to make room in the upper half.
1402 */
1403 if (s->strstart >= wsize+MAX_DIST(s)) {
1404
1405 zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
1406 s->match_start -= wsize;
1407 s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
1408 s->block_start -= (long) wsize;
1409
1410 /* Slide the hash table (could be avoided with 32 bit values
1411 at the expense of memory usage). We slide even when level == 0
1412 to keep the hash table consistent if we switch back to level > 0
1413 later. (Using level 0 permanently is not an optimal usage of
1414 zlib, so we don't care about this pathological case.)
1415 */
1416 n = s->hash_size;
1417 p = &s->head[n];
1418 do {
1419 m = *--p;
1420 *p = (Pos)(m >= wsize ? m-wsize : NIL);
1421 } while (--n);
1422
1423 n = wsize;
1424#ifndef FASTEST
1425 p = &s->prev[n];
1426 do {
1427 m = *--p;
1428 *p = (Pos)(m >= wsize ? m-wsize : NIL);
1429 /* If n is not on any hash chain, prev[n] is garbage but
1430 * its value will never be used.
1431 */
1432 } while (--n);

Callers 6

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

Calls 3

zmemcpyFunction · 0.85
zmemzeroFunction · 0.85
read_bufFunction · 0.70

Tested by

no test coverage detected