X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=src%2Flzx-compress.c;h=26a0c0cbbfb5c38c7f29d3828b4434276418af7b;hp=308c7bf11a728548d6ef60eb3d8ab0211dc52ced;hb=1e8622c4b598811feafbbf0c2c2f2c5bc5d29540;hpb=260370b878a0b1d2351164ae882407ba7de52616 diff --git a/src/lzx-compress.c b/src/lzx-compress.c index 308c7bf1..26a0c0cb 100644 --- a/src/lzx-compress.c +++ b/src/lzx-compress.c @@ -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; @@ -1326,7 +1322,12 @@ lzx_optimize_block(struct lzx_compressor *ctx, struct lzx_block_spec *spec, spec->num_chosen_matches = 0; memset(&freqs, 0, sizeof(freqs)); - for (unsigned i = spec->window_pos; i < spec->window_pos + spec->block_size; ) { + const u8 *window_ptr = &ctx->window[spec->window_pos]; + const u8 *window_end = &window_ptr[spec->block_size]; + struct lzx_match *next_chosen_match = + &ctx->chosen_matches[spec->chosen_matches_start_pos]; + + while (window_ptr != window_end) { struct raw_match raw_match; struct lzx_match lzx_match; @@ -1354,29 +1355,25 @@ lzx_optimize_block(struct lzx_compressor *ctx, struct lzx_block_spec *spec, * null value and therefore cannot * generate such matches. */ BUILD_BUG_ON(LZX_MIN_MATCH_LEN != 2); - lzx_match.data = lzx_tally_literal(ctx->window[i], + lzx_match.data = lzx_tally_literal(*window_ptr++, &freqs); - i += 1; - ctx->chosen_matches[spec->chosen_matches_start_pos + - spec->num_chosen_matches++] - = lzx_match; - lzx_match.data = lzx_tally_literal(ctx->window[i], + *next_chosen_match++ = lzx_match; + lzx_match.data = lzx_tally_literal(*window_ptr++, &freqs); - i += 1; } else { lzx_match.data = lzx_tally_match(raw_match.len, raw_match.offset, &freqs, &ctx->queue); - i += raw_match.len; + window_ptr += raw_match.len; } } else { - lzx_match.data = lzx_tally_literal(ctx->window[i], &freqs); - i += 1; + lzx_match.data = lzx_tally_literal(*window_ptr++, &freqs); } - ctx->chosen_matches[spec->chosen_matches_start_pos + - spec->num_chosen_matches++] = lzx_match; + *next_chosen_match++ = lzx_match; } + spec->num_chosen_matches = next_chosen_match - + &ctx->chosen_matches[spec->chosen_matches_start_pos]; lzx_make_huffman_codes(&freqs, &spec->codes, ctx->num_main_syms); @@ -1592,7 +1589,11 @@ lzx_compress(const void *uncompressed_data, size_t uncompressed_size, * Although this could be disabled by default in all cases, it only * takes around 2-3% of the running time of the slow algorithm to do the * verification. */ -#if defined(ENABLE_LZX_DEBUG) || defined(ENABLE_VERIFY_COMPRESSION) + if (ctx->params.algorithm == WIMLIB_LZX_ALGORITHM_SLOW + #if defined(ENABLE_LZX_DEBUG) || defined(ENABLE_VERIFY_COMPRESSION) + || 1 + #endif + ) { struct wimlib_decompressor *decompressor; @@ -1626,7 +1627,6 @@ lzx_compress(const void *uncompressed_data, size_t uncompressed_size, "data verification!"); } } -#endif return compressed_size; }