Reduce memory usage for inflate

Use Huffman tables with correct sizes instead of always 288
This commit is contained in:
Christian Sandberg
2020-06-20 17:31:32 +02:00
parent 164c81c7d7
commit 8da3cbb64e
2 changed files with 32 additions and 19 deletions

View File

@@ -91,6 +91,12 @@ typedef enum {
do \
{ \
(r)->m_state = 0; \
(r)->m_tables[0].m_pCode_size = (r)->m_code_size_0; \
(r)->m_tables[0].m_pTree = (r)->m_tree_0; \
(r)->m_tables[1].m_pCode_size = (r)->m_code_size_1; \
(r)->m_tables[1].m_pTree = (r)->m_tree_1; \
(r)->m_tables[2].m_pCode_size = (r)->m_code_size_2; \
(r)->m_tables[2].m_pTree = (r)->m_tree_2; \
} \
MZ_MACRO_END
#define tinfl_get_adler32(r) (r)->m_check_adler32
@@ -112,8 +118,9 @@ enum
typedef struct
{
mz_uint8 m_code_size[TINFL_MAX_HUFF_SYMBOLS_0];
mz_int16 m_look_up[TINFL_FAST_LOOKUP_SIZE], m_tree[TINFL_MAX_HUFF_SYMBOLS_0 * 2];
mz_uint8 *m_pCode_size;
mz_int16 *m_pTree;
mz_int16 m_look_up[TINFL_FAST_LOOKUP_SIZE];
} tinfl_huff_table;
#if MINIZ_HAS_64BIT_REGISTERS
@@ -136,6 +143,12 @@ struct tinfl_decompressor_tag
tinfl_bit_buf_t m_bit_buf;
size_t m_dist_from_out_buf_start;
tinfl_huff_table m_tables[TINFL_MAX_HUFF_TABLES];
mz_int16 m_tree_0[TINFL_MAX_HUFF_SYMBOLS_0 * 2];
mz_int16 m_tree_1[TINFL_MAX_HUFF_SYMBOLS_1 * 2];
mz_int16 m_tree_2[TINFL_MAX_HUFF_SYMBOLS_2 * 2];
mz_uint8 m_code_size_0[TINFL_MAX_HUFF_SYMBOLS_0];
mz_uint8 m_code_size_1[TINFL_MAX_HUFF_SYMBOLS_1];
mz_uint8 m_code_size_2[TINFL_MAX_HUFF_SYMBOLS_2];
mz_uint8 m_raw_header[4], m_len_codes[TINFL_MAX_HUFF_SYMBOLS_0 + TINFL_MAX_HUFF_SYMBOLS_1 + 137];
};