]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Deduplicate inflate's fixedtables(), and no longer inline the inffixed tables.
authorHans Kristian Rosbach <hk-git@circlestorm.org>
Thu, 18 Jul 2019 14:17:49 +0000 (16:17 +0200)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Tue, 6 Aug 2019 07:39:26 +0000 (09:39 +0200)
This also reduces the library size by 4120bytes or ~2.9%.

infback.c
inflate.c
inflate.h

index e3886b57af8568fb5f1682b2179c96cefa88df13..27b7b9b033ee53c164cce665dd4c9b071e14a968 100644 (file)
--- a/infback.c
+++ b/infback.c
@@ -17,9 +17,6 @@
 #include "inffast.h"
 #include "inflate_p.h"
 
-/* function prototypes */
-static void fixedtables(struct inflate_state *state);
-
 /*
    strm provides memory allocation functions in zalloc and zfree, or
    NULL to use the library memory allocation functions.
@@ -57,55 +54,6 @@ int ZEXPORT PREFIX(inflateBackInit_)(PREFIX3(stream) *strm, int windowBits, unsi
 }
 
 /*
-   Return state with length and distance decoding tables and index sizes set to
-   fixed code decoding.  Normally this returns fixed tables from inffixed.h.
-   If BUILDFIXED is defined, then instead this routine builds the tables the
-   first time it's called, and returns those tables the first time and
-   thereafter.  This reduces the size of the code by about 2K bytes, in
-   exchange for a little execution time.  However, BUILDFIXED should not be
-   used for threaded applications, since the rewriting of the tables and virgin
-   may not be thread-safe.
- */
-static void fixedtables(struct inflate_state *state) {
-#ifdef BUILDFIXED
-    static int virgin = 1;
-    static code *lenfix, *distfix;
-    static code fixed[544];
-
-    /* build fixed huffman tables if first call (may not be thread safe) */
-    if (virgin) {
-        unsigned sym, bits;
-        static code *next;
-
-        /* literal/length table */
-        sym = 0;
-        while (sym < 144) state->lens[sym++] = 8;
-        while (sym < 256) state->lens[sym++] = 9;
-        while (sym < 280) state->lens[sym++] = 7;
-        while (sym < 288) state->lens[sym++] = 8;
-        next = fixed;
-        lenfix = next;
-        bits = 9;
-        zng_inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
-
-        /* distance table */
-        sym = 0;
-        while (sym < 32) state->lens[sym++] = 5;
-        distfix = next;
-        bits = 5;
-        zng_inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
-
-        /* do this just once */
-        virgin = 0;
-    }
-#else /* !BUILDFIXED */
-#   include "inffixed.h"
-#endif /* BUILDFIXED */
-    state->lencode = lenfix;
-    state->lenbits = 9;
-    state->distcode = distfix;
-    state->distbits = 5;
-}
    Private macros for inflateBack()
    Look in inflate_p.h for macros shared with inflate()
 */
index c07d149a9235904c2b31110df786e6fabad90c77..8caacddc80254a6b4030e664fe94b8b9fd47a747 100644 (file)
--- a/inflate.c
+++ b/inflate.c
 
 /* function prototypes */
 static int inflateStateCheck(PREFIX3(stream) *strm);
-static void fixedtables(struct inflate_state *state);
 static int updatewindow(PREFIX3(stream) *strm, const unsigned char *end, uint32_t copy);
+static uint32_t syncsearch(uint32_t *have, const unsigned char *buf, uint32_t len);
 #ifdef BUILDFIXED
     void makefixed(void);
+#else
+#   include "inffixed.h"
 #endif
-static uint32_t syncsearch(uint32_t *have, const unsigned char *buf, uint32_t len);
 
 static int inflateStateCheck(PREFIX3(stream) *strm) {
     struct inflate_state *state;
@@ -283,7 +284,8 @@ int ZEXPORT PREFIX(inflatePrime)(PREFIX3(stream) *strm, int bits, int value) {
    used for threaded applications, since the rewriting of the tables and virgin
    may not be thread-safe.
  */
-static void fixedtables(struct inflate_state *state) {
+
+void ZLIB_INTERNAL fixedtables(struct inflate_state *state) {
 #ifdef BUILDFIXED
     static int virgin = 1;
     static code *lenfix, *distfix;
@@ -315,8 +317,6 @@ static void fixedtables(struct inflate_state *state) {
         /* do this just once */
         virgin = 0;
     }
-#else /* !BUILDFIXED */
-#   include "inffixed.h"
 #endif /* BUILDFIXED */
     state->lencode = lenfix;
     state->lenbits = 9;
index 01fb1f9b02a2e407fd7089bc6b4ffd697e82a98e..846fcdcf32af9fcaad289286a3c7c4896c3a0e94 100644 (file)
--- a/inflate.h
+++ b/inflate.h
@@ -128,5 +128,6 @@ struct inflate_state {
 };
 
 int ZLIB_INTERNAL inflate_ensure_window(struct inflate_state *state);
+void ZLIB_INTERNAL fixedtables(struct inflate_state *state);
 
 #endif /* INFLATE_H_ */