From 8611ea758cb06df5219939917b0682465f0264ea Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Wed, 20 Aug 2014 04:08:14 +0300 Subject: [PATCH] Don't spend runtime memory on static huffman tables. Build them dynamically as needed, just for blocks needing them, using the same objects as dymanic trees. Given how most deflated files structured, this won't need to be done too often. --- src/tinflate.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/tinflate.c b/src/tinflate.c index 849724f..1638911 100644 --- a/src/tinflate.c +++ b/src/tinflate.c @@ -58,9 +58,6 @@ typedef struct { * -- uninitialized global data (static structures) -- * * --------------------------------------------------- */ -TINF_TREE sltree; /* fixed length/symbol tree */ -TINF_TREE sdtree; /* fixed distance tree */ - /* extra bits and base tables for length codes */ unsigned char length_bits[30]; unsigned short length_base[30]; @@ -369,8 +366,11 @@ static int tinf_inflate_uncompressed_block(TINF_DATA *d) /* inflate a block of data compressed with fixed huffman trees */ static int tinf_inflate_fixed_block(TINF_DATA *d) { + /* build fixed huffman trees */ + tinf_build_fixed_trees(&d->ltree, &d->dtree); + /* decode block using fixed trees */ - return tinf_inflate_block_data(d, &sltree, &sdtree); + return tinf_inflate_block_data(d, &d->ltree, &d->dtree); } /* inflate a block of data compressed with dynamic huffman trees */ @@ -390,9 +390,6 @@ static int tinf_inflate_dynamic_block(TINF_DATA *d) /* initialize global (static) data */ void tinf_init() { - /* build fixed huffman trees */ - tinf_build_fixed_trees(&sltree, &sdtree); - /* build extra bits and base tables */ tinf_build_bits_base(length_bits, length_base, 4, 3); tinf_build_bits_base(dist_bits, dist_base, 2, 1);