]> wimlib.net Git - wimlib/blobdiff - src/lcpit_matchfinder.c
lcpit_matchfinder: fix limiting nice_match_len
[wimlib] / src / lcpit_matchfinder.c
index 67baac4d4c658e76c6934a16192440ba3a755b0f..b5a14e9398656be8c394b92ac525a28d7a4805bd 100644 (file)
@@ -4,11 +4,21 @@
  * A match-finder for Lempel-Ziv compression based on bottom-up construction and
  * traversal of the Longest Common Prefix (LCP) interval tree.
  *
- * Author:     Eric Biggers
- * Year:       2014, 2015
+ * The following copying information applies to this specific source code file:
  *
- * The author dedicates this file to the public domain.
- * You can do whatever you want with this file.
+ * Written in 2014-2015 by Eric Biggers <ebiggers3@gmail.com>
+ *
+ * To the extent possible under law, the author(s) have dedicated all copyright
+ * and related and neighboring rights to this software to the public domain
+ * worldwide via the Creative Commons Zero 1.0 Universal Public Domain
+ * Dedication (the "CC0").
+ *
+ * This software is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the CC0 for more details.
+ *
+ * You should have received a copy of the CC0 along with this software; if not
+ * see <http://creativecommons.org/publicdomain/zero/1.0/>.
  */
 
 #ifdef HAVE_CONFIG_H
@@ -274,7 +284,7 @@ build_LCPIT(u32 intervals[restrict], u32 pos_data[restrict], const u32 n)
  * around by just continuing until we get to a link that actually takes us
  * higher in the tree.  This can be described as a lazy-update scheme.
  */
-static inline u32
+static forceinline u32
 lcpit_advance_one_byte(const u32 cur_pos,
                       u32 pos_data[restrict],
                       u32 intervals[restrict],
@@ -476,7 +486,7 @@ build_LCPIT_huge(u64 intervals64[restrict], u32 pos_data[restrict], const u32 n)
 
 /* Like lcpit_advance_one_byte(), but for buffers larger than
  * MAX_NORMAL_BUFSIZE.  */
-static inline u32
+static forceinline u32
 lcpit_advance_one_byte_huge(const u32 cur_pos,
                            u32 pos_data[restrict],
                            u64 intervals64[restrict],
@@ -528,14 +538,14 @@ lcpit_advance_one_byte_huge(const u32 cur_pos,
        return matchptr - matches;
 }
 
-static inline u64
+static forceinline u64
 get_pos_data_size(size_t max_bufsize)
 {
        return (u64)max((u64)max_bufsize + PREFETCH_SAFETY,
                        DIVSUFSORT_TMP_LEN) * sizeof(u32);
 }
 
-static inline u64
+static forceinline u64
 get_intervals_size(size_t max_bufsize)
 {
        return ((u64)max_bufsize + PREFETCH_SAFETY) *
@@ -583,9 +593,7 @@ lcpit_matchfinder_init(struct lcpit_matchfinder *mf, size_t max_bufsize,
        }
 
        mf->min_match_len = min_match_len;
-       mf->nice_match_len = min(nice_match_len,
-                                (max_bufsize <= MAX_NORMAL_BUFSIZE) ?
-                                LCP_MAX : HUGE_LCP_MAX);
+       mf->orig_nice_match_len = nice_match_len;
        return true;
 }
 
@@ -603,7 +611,7 @@ lcpit_matchfinder_init(struct lcpit_matchfinder *mf, size_t max_bufsize,
  * References:
  *
  *     Y. Mori.  libdivsufsort, a lightweight suffix-sorting library.
- *     https://code.google.com/p/libdivsufsort/.
+ *     https://github.com/y-256/libdivsufsort
  *
  *     G. Nong, S. Zhang, and W.H. Chan.  2009.  Linear Suffix Array
  *     Construction by Almost Pure Induced-Sorting.  Data Compression
@@ -654,6 +662,7 @@ lcpit_matchfinder_load_buffer(struct lcpit_matchfinder *mf, const u8 *T, u32 n)
        build_SA(mf->intervals, T, n, mf->pos_data);
        build_ISA(mf->pos_data, mf->intervals, n);
        if (n <= MAX_NORMAL_BUFSIZE) {
+               mf->nice_match_len = min(mf->orig_nice_match_len, LCP_MAX);
                for (u32 i = 0; i < PREFETCH_SAFETY; i++) {
                        mf->intervals[n + i] = 0;
                        mf->pos_data[n + i] = 0;
@@ -663,6 +672,7 @@ lcpit_matchfinder_load_buffer(struct lcpit_matchfinder *mf, const u8 *T, u32 n)
                build_LCPIT(mf->intervals, mf->pos_data, n);
                mf->huge_mode = false;
        } else {
+               mf->nice_match_len = min(mf->orig_nice_match_len, HUGE_LCP_MAX);
                for (u32 i = 0; i < PREFETCH_SAFETY; i++) {
                        mf->intervals64[n + i] = 0;
                        mf->pos_data[n + i] = 0;