X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Flz77.c;h=b5495da74d1599cd59e12cc8ef65c495550eba55;hb=4f433755e8f9ef79dbb4699430d047f74e338e82;hp=887b874506857251b2bda6c92809c3d008777222;hpb=49a63aa13cdeb4c1348697ccd92207a1a65ec7b0;p=wimlib diff --git a/src/lz77.c b/src/lz77.c index 887b8745..b5495da7 100644 --- a/src/lz77.c +++ b/src/lz77.c @@ -30,24 +30,15 @@ # include #endif -#include "wimlib/compress.h" +#include "wimlib/compress_common.h" #include "wimlib/util.h" #include -#define LZ_MIN_MATCH 3 - #define HASH_BITS 15 #define HASH_SIZE (1 << HASH_BITS) #define HASH_MASK (HASH_SIZE - 1) - -#if LZ_MIN_MATCH == 2 -# define HASH_SHIFT 8 -#elif LZ_MIN_MATCH == 3 -# define HASH_SHIFT 5 -#else -#error "Invalid LZ_MIN_MATCH" -#endif +#define HASH_SHIFT 5 /* Hash function, based on code from zlib. This function will update and return * the hash value @hash for the string ending on the additional input character @@ -82,7 +73,7 @@ insert_string(input_idx_t hash_tab[], input_idx_t prev_tab[], const u8 window[], unsigned str_pos, unsigned hash) { - hash = update_hash(hash, window[str_pos + LZ_MIN_MATCH - 1]); + hash = update_hash(hash, window[str_pos + 2]); prev_tab[str_pos] = hash_tab[hash]; hash_tab[hash] = str_pos; return hash; @@ -95,18 +86,18 @@ insert_string(input_idx_t hash_tab[], input_idx_t prev_tab[], * @window: The window of uncompressed data. * @bytes_remaining: The number of bytes remaining in the window. * @strstart: The index of the start of the string in the window that - * we are trying to find a match for. + * we are trying to find a match for. * @prev_tab: The array of prev pointers for the hash table. * @cur_match: The index of the head of the hash chain for matches - * having the hash value of the string beginning - * at index @strstart. + * having the hash value of the string beginning + * at index @strstart. * @prev_len: The length of the match that was found for the string - * beginning at (@strstart - 1). + * beginning at (@strstart - 1). * @match_start_ret: A location into which the index of the start of the - * match will be returned. + * match will be returned. * @params: Parameters that affect how long the search will proceed - * before going with the best that has been found - * so far. + * before going with the best that has been found + * so far. * @min_start_pos: If the chain reaches a match starting before this * position (including the end-of-chain 0), the search will * be terminated. @@ -202,18 +193,18 @@ longest_match(const u8 window[], unsigned bytes_remaining, * @record_literal: Consumer for literals. * @record_ctx: Context passed to @record_match and @record_literal. * @params: Structure that contains parameters that affect how the - * analysis proceeds (mainly how good the matches - * have to be). + * analysis proceeds (mainly how good the matches + * have to be). * @prev_tab: Temporary space containing least @window_size elements. */ void -lz_analyze_block(const u8 window[], +lz_analyze_block(const u8 window[restrict], input_idx_t window_size, lz_record_match_t record_match, lz_record_literal_t record_literal, void *record_ctx, const struct lz_params *params, - input_idx_t prev_tab[]) + input_idx_t prev_tab[restrict]) { unsigned cur_input_pos = 0; unsigned hash = 0; @@ -291,21 +282,17 @@ lz_analyze_block(const u8 window[], /* Do not insert strings in hash table beyond this. */ unsigned max_insert = window_size - params->min_match; -#if LZ_MIN_MATCH == 2 - if (prev_len >= 3) -#endif - { - prev_len -= 2; - - do { - if (++cur_input_pos <= max_insert) { - hash = insert_string(hash_tab, prev_tab, - window, - cur_input_pos, - hash); - } - } while (--prev_len != 0); - } + + prev_len -= 2; + + do { + if (++cur_input_pos <= max_insert) { + hash = insert_string(hash_tab, prev_tab, + window, + cur_input_pos, + hash); + } + } while (--prev_len != 0); match_available = false; match_len = params->min_match - 1; } else if (match_available) {