]> wimlib.net Git - wimlib/commitdiff
bt_matchfinder: add BT_MATCHFINDER_REQUIRED_NBYTES
authorEric Biggers <ebiggers3@gmail.com>
Fri, 25 Sep 2015 03:46:48 +0000 (22:46 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Sun, 27 Sep 2015 14:41:30 +0000 (09:41 -0500)
include/wimlib/bt_matchfinder.h
src/lzx_compress.c
src/xpress_compress.c

index c7f2ba8eaebd9c039d9d7441724d598de2dd6541..3d295cd91fe8e50afb1c5479ce9d62a9c9c5dd6a 100644 (file)
@@ -123,6 +123,11 @@ TEMPLATED(bt_right_child)(struct TEMPLATED(bt_matchfinder) *mf, u32 node)
        return &mf->child_tab[(node << 1) + 1];
 }
 
        return &mf->child_tab[(node << 1) + 1];
 }
 
+/* The minimum permissible value of 'max_len' for bt_matchfinder_get_matches()
+ * and bt_matchfinder_skip_position().  There must be sufficiently many bytes
+ * remaining to load a 32-bit integer from the *next* position.  */
+#define BT_MATCHFINDER_REQUIRED_NBYTES 5
+
 /* Advance the binary tree matchfinder by one byte, optionally recording
  * matches.  @record_matches should be a compile-time constant.  */
 static inline struct lz_match *
 /* Advance the binary tree matchfinder by one byte, optionally recording
  * matches.  @record_matches should be a compile-time constant.  */
 static inline struct lz_match *
@@ -266,7 +271,8 @@ TEMPLATED(bt_matchfinder_advance_one_byte)(struct TEMPLATED(bt_matchfinder) * co
  *     The current position in the input buffer (the position of the sequence
  *     being matched against).
  * @max_len
  *     The current position in the input buffer (the position of the sequence
  *     being matched against).
  * @max_len
- *     The maximum permissible match length at this position.  Must be >= 5.
+ *     The maximum permissible match length at this position.  Must be >=
+ *     BT_MATCHFINDER_REQUIRED_NBYTES.
  * @nice_len
  *     Stop searching if a match of at least this length is found.
  *     Must be <= @max_len.
  * @nice_len
  *     Stop searching if a match of at least this length is found.
  *     Must be <= @max_len.
index 33943af7fa41d1e4d4cb3f4a66bdbc4acd27e93e..ca9906e7daef7c057994792ba567278a19a0fc95 100644 (file)
@@ -1809,7 +1809,7 @@ lzx_compress_near_optimal(struct lzx_compressor *c,
                        if (unlikely(max_len > in_end - in_next)) {
                                max_len = in_end - in_next;
                                nice_len = min(max_len, nice_len);
                        if (unlikely(max_len > in_end - in_next)) {
                                max_len = in_end - in_next;
                                nice_len = min(max_len, nice_len);
-                               if (unlikely(max_len < 5)) {
+                               if (unlikely(max_len < BT_MATCHFINDER_REQUIRED_NBYTES)) {
                                        in_next++;
                                        cache_ptr->length = 0;
                                        cache_ptr++;
                                        in_next++;
                                        cache_ptr->length = 0;
                                        cache_ptr++;
@@ -1849,7 +1849,7 @@ lzx_compress_near_optimal(struct lzx_compressor *c,
                                        if (unlikely(max_len > in_end - in_next)) {
                                                max_len = in_end - in_next;
                                                nice_len = min(max_len, nice_len);
                                        if (unlikely(max_len > in_end - in_next)) {
                                                max_len = in_end - in_next;
                                                nice_len = min(max_len, nice_len);
-                                               if (unlikely(max_len < 5)) {
+                                               if (unlikely(max_len < BT_MATCHFINDER_REQUIRED_NBYTES)) {
                                                        in_next++;
                                                        cache_ptr->length = 0;
                                                        cache_ptr++;
                                                        in_next++;
                                                        cache_ptr->length = 0;
                                                        cache_ptr++;
index 5c3249d05ec79eb61447cd2d0e15b078005e5841..a04bc52d207adf35db24bcb3725cefdcef8d897a 100644 (file)
@@ -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 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;
                        break;
 
                matches = cache_ptr;
@@ -955,7 +956,8 @@ 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) {
                 * 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 {
                                break;
                        --best_len;
                        do {