]> wimlib.net Git - wimlib/blobdiff - src/xpress_compress.c
Rename 'pos_t' to 'mf_pos_t'
[wimlib] / src / xpress_compress.c
index 6750160450ae76ec8fa4991f78867f89eea147fe..b57d0ea62355157dbf72a16c2f8c75bd503e2ab4 100644 (file)
 #define MIN_LEVEL_FOR_NEAR_OPTIMAL     60
 
 /*
- * The maximum window order for the matchfinder.  This must be the base 2
- * logarithm of the maximum buffer size.
+ * Matchfinder definitions.  For XPRESS, only a 16-bit matchfinder is needed.
  */
-#define MATCHFINDER_MAX_WINDOW_ORDER   16
+#define mf_pos_t       u16
+#define MF_SUFFIX
 
 /*
  * Note: although XPRESS can potentially use a sliding window, it isn't well
@@ -59,8 +59,6 @@
  * optimizations.
  */
 
-#include <string.h>
-
 #include "wimlib/bitops.h"
 #include "wimlib/compress_common.h"
 #include "wimlib/compressor_ops.h"
@@ -531,6 +529,7 @@ xpress_compress_greedy(struct xpress_compressor * restrict c,
        const u8 * const in_end = in_begin + in_nbytes;
        struct xpress_item *next_chosen_item = c->chosen_items;
        unsigned len_3_too_far;
+       u32 next_hashes[2] = {};
 
        if (in_nbytes <= 8192)
                len_3_too_far = 2048;
@@ -545,11 +544,12 @@ xpress_compress_greedy(struct xpress_compressor * restrict c,
 
                length = hc_matchfinder_longest_match(&c->hc_mf,
                                                      in_begin,
-                                                     in_next,
+                                                     in_next - in_begin,
                                                      XPRESS_MIN_MATCH_LEN - 1,
                                                      in_end - in_next,
                                                      min(in_end - in_next, c->nice_match_length),
                                                      c->max_search_depth,
+                                                     next_hashes,
                                                      &offset);
                if (length >= XPRESS_MIN_MATCH_LEN &&
                    !(length == XPRESS_MIN_MATCH_LEN && offset >= len_3_too_far))
@@ -560,9 +560,10 @@ xpress_compress_greedy(struct xpress_compressor * restrict c,
                        in_next += 1;
                        hc_matchfinder_skip_positions(&c->hc_mf,
                                                      in_begin,
-                                                     in_next,
-                                                     in_end,
-                                                     length - 1);
+                                                     in_next - in_begin,
+                                                     in_end - in_begin,
+                                                     length - 1,
+                                                     next_hashes);
                        in_next += length - 1;
                } else {
                        /* No match found  */
@@ -591,6 +592,7 @@ xpress_compress_lazy(struct xpress_compressor * restrict c,
        const u8 * const in_end = in_begin + in_nbytes;
        struct xpress_item *next_chosen_item = c->chosen_items;
        unsigned len_3_too_far;
+       u32 next_hashes[2] = {};
 
        if (in_nbytes <= 8192)
                len_3_too_far = 2048;
@@ -608,11 +610,12 @@ xpress_compress_lazy(struct xpress_compressor * restrict c,
                /* Find the longest match at the current position.  */
                cur_len = hc_matchfinder_longest_match(&c->hc_mf,
                                                       in_begin,
-                                                      in_next,
+                                                      in_next - in_begin,
                                                       XPRESS_MIN_MATCH_LEN - 1,
                                                       in_end - in_next,
                                                       min(in_end - in_next, c->nice_match_length),
                                                       c->max_search_depth,
+                                                      next_hashes,
                                                       &cur_offset);
                in_next += 1;
 
@@ -637,9 +640,10 @@ xpress_compress_lazy(struct xpress_compressor * restrict c,
 
                        hc_matchfinder_skip_positions(&c->hc_mf,
                                                      in_begin,
-                                                     in_next,
-                                                     in_end,
-                                                     cur_len - 1);
+                                                     in_next - in_begin,
+                                                     in_end - in_begin,
+                                                     cur_len - 1,
+                                                     next_hashes);
                        in_next += cur_len - 1;
                        continue;
                }
@@ -662,11 +666,12 @@ xpress_compress_lazy(struct xpress_compressor * restrict c,
                 */
                next_len = hc_matchfinder_longest_match(&c->hc_mf,
                                                        in_begin,
-                                                       in_next,
+                                                       in_next - in_begin,
                                                        cur_len,
                                                        in_end - in_next,
                                                        min(in_end - in_next, c->nice_match_length),
                                                        c->max_search_depth / 2,
+                                                       next_hashes,
                                                        &next_offset);
                in_next += 1;
 
@@ -685,9 +690,10 @@ xpress_compress_lazy(struct xpress_compressor * restrict c,
                                xpress_record_match(c, cur_len, cur_offset);
                        hc_matchfinder_skip_positions(&c->hc_mf,
                                                      in_begin,
-                                                     in_next,
-                                                     in_end,
-                                                     cur_len - 2);
+                                                     in_next - in_begin,
+                                                     in_end - in_begin,
+                                                     cur_len - 2,
+                                                     next_hashes);
                        in_next += cur_len - 2;
                        continue;
                }
@@ -902,10 +908,9 @@ xpress_find_matches(struct xpress_compressor * restrict c,
        const u8 *in_next = in_begin;
        const u8 * const in_end = in_begin + in_nbytes;
        struct lz_match *cache_ptr = c->match_cache;
-       u32 next_hash;
+       u32 next_hash = 0;
 
        bt_matchfinder_init(&c->bt_mf);
-       next_hash = bt_matchfinder_hash_3_bytes(in_next);
 
        do {
                struct lz_match *matches;
@@ -931,8 +936,7 @@ xpress_find_matches(struct xpress_compressor * restrict c,
                cache_ptr =
                        bt_matchfinder_get_matches(&c->bt_mf,
                                                   in_begin,
-                                                  in_next,
-                                                  XPRESS_MIN_MATCH_LEN,
+                                                  in_next - in_begin,
                                                   in_end - in_next,
                                                   min(in_end - in_next, c->nice_match_length),
                                                   c->max_search_depth,
@@ -959,8 +963,8 @@ xpress_find_matches(struct xpress_compressor * restrict c,
                        do {
                                bt_matchfinder_skip_position(&c->bt_mf,
                                                             in_begin,
-                                                            in_next,
-                                                            in_end,
+                                                            in_next - in_begin,
+                                                            in_end - in_next,
                                                             min(in_end - in_next,
                                                                 c->nice_match_length),
                                                             c->max_search_depth,
@@ -1068,8 +1072,7 @@ xpress_create_compressor(size_t max_bufsize, unsigned compression_level,
        if (max_bufsize > XPRESS_MAX_BUFSIZE)
                return WIMLIB_ERR_INVALID_PARAM;
 
-       c = ALIGNED_MALLOC(xpress_get_compressor_size(max_bufsize, compression_level),
-                          MATCHFINDER_ALIGNMENT);
+       c = MALLOC(xpress_get_compressor_size(max_bufsize, compression_level));
        if (!c)
                goto oom0;
 
@@ -1129,7 +1132,7 @@ xpress_create_compressor(size_t max_bufsize, unsigned compression_level,
        return 0;
 
 oom1:
-       ALIGNED_FREE(c);
+       FREE(c);
 oom0:
        return WIMLIB_ERR_NOMEM;
 }
@@ -1164,7 +1167,7 @@ xpress_free_compressor(void *_c)
        } else
 #endif
                FREE(c->chosen_items);
-       ALIGNED_FREE(c);
+       FREE(c);
 }
 
 const struct compressor_ops xpress_compressor_ops = {