]> wimlib.net Git - wimlib/blobdiff - src/lzx-compress.c
Optimize Huffman code generation
[wimlib] / src / lzx-compress.c
index e1b65c7c18573bb721bd71ed6ab457a0892ca911..edda90aefc1a59cc96bc37779b32df762a1b4521 100644 (file)
@@ -179,9 +179,9 @@ typedef u32 block_cost_t;
 
 /* Codewords for the LZX main, length, and aligned offset Huffman codes  */
 struct lzx_codewords {
-       u16 main[LZX_MAINCODE_MAX_NUM_SYMBOLS];
-       u16 len[LZX_LENCODE_NUM_SYMBOLS];
-       u16 aligned[LZX_ALIGNEDCODE_NUM_SYMBOLS];
+       u32 main[LZX_MAINCODE_MAX_NUM_SYMBOLS];
+       u32 len[LZX_LENCODE_NUM_SYMBOLS];
+       u32 aligned[LZX_ALIGNEDCODE_NUM_SYMBOLS];
 };
 
 /* Codeword lengths (in bits) for the LZX main, length, and aligned offset
@@ -456,9 +456,6 @@ lzx_write_match(struct output_bitstream *out, int block_type,
         * MIN_MATCH_LEN. */
        if (match_len_minus_2 < LZX_NUM_PRIMARY_LENS) {
                len_header = match_len_minus_2;
-               /* No length footer-- mark it with a special
-                * value. */
-               len_footer = (unsigned)(-1);
        } else {
                len_header = LZX_NUM_PRIMARY_LENS;
                len_footer = match_len_minus_2 - LZX_NUM_PRIMARY_LENS;
@@ -478,10 +475,9 @@ lzx_write_match(struct output_bitstream *out, int block_type,
 
        /* If there is a length footer, output it using the
         * length Huffman code. */
-       if (len_footer != (unsigned)(-1)) {
+       if (len_header == LZX_NUM_PRIMARY_LENS)
                bitstream_put_bits(out, codes->codewords.len[len_footer],
                                   codes->lens.len[len_footer]);
-       }
 
        num_extra_bits = lzx_get_num_extra_bits(position_slot);
 
@@ -523,7 +519,7 @@ lzx_build_precode(const u8 lens[restrict],
                  input_idx_t precode_freqs[restrict LZX_PRECODE_NUM_SYMBOLS],
                  u8 output_syms[restrict num_syms],
                  u8 precode_lens[restrict LZX_PRECODE_NUM_SYMBOLS],
-                 u16 precode_codewords[restrict LZX_PRECODE_NUM_SYMBOLS],
+                 u32 precode_codewords[restrict LZX_PRECODE_NUM_SYMBOLS],
                  unsigned *num_additional_bits_ret)
 {
        memset(precode_freqs, 0,
@@ -692,7 +688,7 @@ lzx_write_compressed_code(struct output_bitstream *out,
        input_idx_t precode_freqs[LZX_PRECODE_NUM_SYMBOLS];
        u8 output_syms[num_syms];
        u8 precode_lens[LZX_PRECODE_NUM_SYMBOLS];
-       u16 precode_codewords[LZX_PRECODE_NUM_SYMBOLS];
+       u32 precode_codewords[LZX_PRECODE_NUM_SYMBOLS];
        unsigned i;
        unsigned num_output_syms;
        u8 precode_sym;