From: Nathan Moinvaziri Date: Fri, 19 Jun 2020 03:22:09 +0000 (-0700) Subject: Only calculate inflate chunk size once and store it for future use for performance. X-Git-Tag: 1.9.9-b1~174 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=10be7c55f66e08f97c15afb5c5af985094155b5a;p=thirdparty%2Fzlib-ng.git Only calculate inflate chunk size once and store it for future use for performance. --- diff --git a/inffast.c b/inffast.c index 57d3ce4ea..27c29d9ed 100644 --- a/inffast.c +++ b/inffast.c @@ -270,7 +270,7 @@ void ZLIB_INTERNAL zng_inflate_fast(PREFIX3(stream) *strm, unsigned long start) operations can write beyond `out+len` so long as they stay within 258 bytes of `out`. */ - if (dist >= len || dist >= functable.chunksize()) + if (dist >= len || dist >= state->chunksize) out = functable.chunkcopy(out, out - dist, len); else out = functable.chunkmemset(out, dist, len); diff --git a/inflate.c b/inflate.c index 69fc0e1f7..340f854b7 100644 --- a/inflate.c +++ b/inflate.c @@ -155,6 +155,7 @@ int32_t ZEXPORT PREFIX(inflateInit2_)(PREFIX3(stream) *strm, int32_t windowBits, state->strm = strm; state->window = NULL; state->mode = HEAD; /* to pass state test in inflateReset2() */ + state->chunksize = functable.chunksize(); ret = PREFIX(inflateReset2)(strm, windowBits); if (ret != Z_OK) { ZFREE_STATE(strm, state); @@ -203,10 +204,10 @@ int ZLIB_INTERNAL inflate_ensure_window(struct inflate_state *state) { /* if it hasn't been done already, allocate space for the window */ if (state->window == NULL) { unsigned wsize = 1U << state->wbits; - state->window = (unsigned char *) ZALLOC_WINDOW(state->strm, wsize + functable.chunksize(), sizeof(unsigned char)); + state->window = (unsigned char *) ZALLOC_WINDOW(state->strm, wsize + state->chunksize, sizeof(unsigned char)); if (state->window == Z_NULL) return 1; - memset(state->window + wsize, 0, functable.chunksize()); + memset(state->window + wsize, 0, state->chunksize); } /* if window not in use yet, initialize */ diff --git a/inflate.h b/inflate.h index 384459ab2..d9dda7902 100644 --- a/inflate.h +++ b/inflate.h @@ -126,6 +126,7 @@ struct inflate_state { int sane; /* if false, allow invalid distance too far */ int back; /* bits back of last unprocessed length/lit */ unsigned was; /* initial length of match */ + uint32_t chunksize; /* size of memory copying chunk */ }; int ZLIB_INTERNAL inflate_ensure_window(struct inflate_state *state);