MCPcopy Create free account
hub / github.com/MariaDB/server / deflateSetDictionary

Function deflateSetDictionary

zlib/deflate.c:559–622  ·  view source on GitHub ↗

========================================================================= */

Source from the content-addressed store, hash-verified

557
558/* ========================================================================= */
559int ZEXPORT deflateSetDictionary(z_streamp strm, const Bytef *dictionary,
560 uInt dictLength) {
561 deflate_state *s;
562 uInt str, n;
563 int wrap;
564 unsigned avail;
565 z_const unsigned char *next;
566
567 if (deflateStateCheck(strm) || dictionary == Z_NULL)
568 return Z_STREAM_ERROR;
569 s = strm->state;
570 wrap = s->wrap;
571 if (wrap == 2 || (wrap == 1 && s->status != INIT_STATE) || s->lookahead)
572 return Z_STREAM_ERROR;
573
574 /* when using zlib wrappers, compute Adler-32 for provided dictionary */
575 if (wrap == 1)
576 strm->adler = adler32(strm->adler, dictionary, dictLength);
577 s->wrap = 0; /* avoid computing Adler-32 in read_buf */
578
579 /* if dictionary would fill window, just replace the history */
580 if (dictLength >= s->w_size) {
581 if (wrap == 0) { /* already empty otherwise */
582 CLEAR_HASH(s);
583 s->strstart = 0;
584 s->block_start = 0L;
585 s->insert = 0;
586 }
587 dictionary += dictLength - s->w_size; /* use the tail */
588 dictLength = s->w_size;
589 }
590
591 /* insert dictionary into window and hash */
592 avail = strm->avail_in;
593 next = strm->next_in;
594 strm->avail_in = dictLength;
595 strm->next_in = (z_const Bytef *)dictionary;
596 fill_window(s);
597 while (s->lookahead >= MIN_MATCH) {
598 str = s->strstart;
599 n = s->lookahead - (MIN_MATCH-1);
600 do {
601 UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
602#ifndef FASTEST
603 s->prev[str & s->w_mask] = s->head[s->ins_h];
604#endif
605 s->head[s->ins_h] = (Pos)str;
606 str++;
607 } while (--n);
608 s->strstart = str;
609 s->lookahead = MIN_MATCH-1;
610 fill_window(s);
611 }
612 s->strstart += s->lookahead;
613 s->block_start = (long)s->strstart;
614 s->insert = s->lookahead;
615 s->lookahead = 0;
616 s->match_length = s->prev_length = MIN_MATCH-1;

Callers

nothing calls this directly

Calls 3

deflateStateCheckFunction · 0.85
adler32Function · 0.85
fill_windowFunction · 0.85

Tested by

no test coverage detected