X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=src%2Fxpress_compress.c;h=d8cb7697deb9732eeab7a4e33c1d6093abb618fc;hp=ba7a9af7272ecb3510d6a6ab04e7fec0319dd3cd;hb=993d197cac3a09508f2afefe0e2a620d7e43fa1a;hpb=5ec910e4e9126a37eed1ff199d55a1952c76e0f7 diff --git a/src/xpress_compress.c b/src/xpress_compress.c index ba7a9af7..d8cb7697 100644 --- a/src/xpress_compress.c +++ b/src/xpress_compress.c @@ -212,7 +212,7 @@ struct xpress_output_bitstream { /* Pointer to the start of the output buffer. */ u8 *start; - /* Pointer to the location in the ouput buffer at which to write the + /* Pointer to the location in the output buffer at which to write the * next 16 bits. */ u8 *next_bits; @@ -292,7 +292,7 @@ xpress_write_bits(struct xpress_output_bitstream *os, if (os->bitcount > 16) { os->bitcount -= 16; if (os->end - os->next_byte >= 2) { - put_unaligned_u16_le(os->bitbuf >> os->bitcount, os->next_bits); + put_unaligned_le16(os->bitbuf >> os->bitcount, os->next_bits); os->next_bits = os->next_bits2; os->next_bits2 = os->next_byte; os->next_byte += 2; @@ -317,7 +317,7 @@ static inline void xpress_write_u16(struct xpress_output_bitstream *os, u16 v) { if (os->end - os->next_byte >= 2) { - put_unaligned_u16_le(v, os->next_byte); + put_unaligned_le16(v, os->next_byte); os->next_byte += 2; } } @@ -332,8 +332,8 @@ xpress_flush_output(struct xpress_output_bitstream *os) if (os->end - os->next_byte < 2) return 0; - put_unaligned_u16_le(os->bitbuf << (16 - os->bitcount), os->next_bits); - put_unaligned_u16_le(0, os->next_bits2); + put_unaligned_le16(os->bitbuf << (16 - os->bitcount), os->next_bits); + put_unaligned_le16(0, os->next_bits2); return os->next_byte - os->start; } @@ -907,7 +907,7 @@ xpress_find_matches(struct xpress_compressor * restrict c, const u8 * const in_begin = in; const u8 *in_next = in_begin; struct lz_match *cache_ptr = c->match_cache; - u32 next_hash = 0; + u32 next_hashes[2] = {}; u32 max_len = in_nbytes; u32 nice_len = min(max_len, c->nice_match_length); @@ -920,7 +920,8 @@ xpress_find_matches(struct xpress_compressor * restrict c, /* If we've found so many matches that the cache might overflow * if we keep finding more, then stop finding matches. This * case is very unlikely. */ - if (unlikely(cache_ptr >= c->cache_overflow_mark || max_len < 5)) + if (unlikely(cache_ptr >= c->cache_overflow_mark || + max_len < BT_MATCHFINDER_REQUIRED_NBYTES)) break; matches = cache_ptr; @@ -935,7 +936,7 @@ xpress_find_matches(struct xpress_compressor * restrict c, max_len, nice_len, c->max_search_depth, - &next_hash, + next_hashes, &best_len, cache_ptr); cache_ptr->length = cache_ptr - matches; @@ -955,17 +956,17 @@ xpress_find_matches(struct xpress_compressor * restrict c, * highly compressible, so it doesn't matter as much what we do. */ if (best_len >= nice_len) { - if (unlikely(best_len + 5 >= max_len)) + if (unlikely(best_len + + BT_MATCHFINDER_REQUIRED_NBYTES >= max_len)) break; --best_len; do { bt_matchfinder_skip_position(&c->bt_mf, in_begin, in_next - in_begin, - max_len, nice_len, c->max_search_depth, - &next_hash); + next_hashes); cache_ptr->length = 0; cache_ptr->offset = *in_next++; cache_ptr++; @@ -1090,12 +1091,12 @@ xpress_create_compressor(size_t max_bufsize, unsigned compression_level, if (compression_level < 30) { c->impl = xpress_compress_greedy; - c->max_search_depth = (compression_level * 24) / 16; - c->nice_match_length = (compression_level * 48) / 16; + c->max_search_depth = (compression_level * 30) / 16; + c->nice_match_length = (compression_level * 60) / 16; } else { c->impl = xpress_compress_lazy; - c->max_search_depth = (compression_level * 24) / 32; - c->nice_match_length = (compression_level * 48) / 32; + c->max_search_depth = (compression_level * 30) / 32; + c->nice_match_length = (compression_level * 60) / 32; /* xpress_compress_lazy() needs max_search_depth >= 2 * because it halves the max_search_depth when @@ -1122,8 +1123,8 @@ xpress_create_compressor(size_t max_bufsize, unsigned compression_level, &c->match_cache[max_bufsize * CACHE_RESERVE_PER_POS]; c->impl = xpress_compress_near_optimal; - c->max_search_depth = (compression_level * 32) / 100; - c->nice_match_length = (compression_level * 50) / 100; + c->max_search_depth = (compression_level * 28) / 100; + c->nice_match_length = (compression_level * 56) / 100; c->num_optim_passes = compression_level / 40; } #endif /* SUPPORT_NEAR_OPTIMAL_PARSING */