MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / updatewindow

Function updatewindow

zlib/inflate.c:323–371  ·  view source on GitHub ↗

Update the window with the last wsize (normally 32K) bytes written before returning. If window does not exist yet, create it. This is only called when a window is already in use, or when output has been written during this inflate call, but the end of the deflate stream has not been reached yet. It is also called to create a window for dictionary data when a dictionary is loaded.

(strm, out)

Source from the content-addressed store, hash-verified

321 The advantage may be dependent on the size of the processor's data caches.
322 */
323local int updatewindow(strm, out)
324z_streamp strm;
325unsigned out;
326{
327 struct inflate_state FAR *state;
328 unsigned copy, dist;
329
330 state = (struct inflate_state FAR *)strm->state;
331
332 /* if it hasn't been done already, allocate space for the window */
333 if (state->window == Z_NULL) {
334 state->window = (unsigned char FAR *)
335 ZALLOC(strm, 1U << state->wbits,
336 sizeof(unsigned char));
337 if (state->window == Z_NULL) return 1;
338 }
339
340 /* if window not in use yet, initialize */
341 if (state->wsize == 0) {
342 state->wsize = 1U << state->wbits;
343 state->write = 0;
344 state->whave = 0;
345 }
346
347 /* copy state->wsize or less output bytes into the circular window */
348 copy = out - strm->avail_out;
349 if (copy >= state->wsize) {
350 zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
351 state->write = 0;
352 state->whave = state->wsize;
353 }
354 else {
355 dist = state->wsize - state->write;
356 if (dist > copy) dist = copy;
357 zmemcpy(state->window + state->write, strm->next_out - copy, dist);
358 copy -= dist;
359 if (copy) {
360 zmemcpy(state->window, strm->next_out - copy, copy);
361 state->write = copy;
362 state->whave = state->wsize;
363 }
364 else {
365 state->write += dist;
366 if (state->write == state->wsize) state->write = 0;
367 if (state->whave < state->wsize) state->whave += dist;
368 }
369 }
370 return 0;
371}
372
373/* Macros for inflate(): */
374

Callers 1

inflate.cFile · 0.85

Calls 1

zmemcpyFunction · 0.85

Tested by

no test coverage detected