]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Only calculate inflate chunk size once and store it for future use for performance.
authorNathan Moinvaziri <nathan@nathanm.com>
Fri, 19 Jun 2020 03:22:09 +0000 (20:22 -0700)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Sun, 28 Jun 2020 09:16:05 +0000 (11:16 +0200)
inffast.c
inflate.c
inflate.h

index 57d3ce4ea0aeb6dac5e88a18ec4fd36f936c8c12..27c29d9ed50fcf4292273ff1f67b365b3be0ec79 100644 (file)
--- 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);
index 69fc0e1f7023dbfcee0e3b61a1ac51567e320eba..340f854b79861a136f2aeeb394d3b1a37f018c46 100644 (file)
--- 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 */
index 384459ab2493a592f66ca4557c4036afac954809..d9dda7902952da5395866930b425667c69f9daca 100644 (file)
--- 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);