deflate-ruby 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CLAUDE.md +95 -92
- data/GEM_VERIFICATION_REPORT.md +140 -0
- data/LICENSE.txt +6 -6
- data/README.md +87 -65
- data/Rakefile +23 -0
- data/ext/deflate_ruby/{libdeflate/lib/x86/adler32_impl.h → adler32_impl.h} +8 -7
- data/ext/deflate_ruby/common_defs.h +748 -0
- data/ext/deflate_ruby/{libdeflate/lib/x86/cpu_features.c → cpu_features.c} +46 -16
- data/ext/deflate_ruby/{libdeflate/lib/x86/cpu_features.h → cpu_features.h} +2 -1
- data/ext/deflate_ruby/{libdeflate/lib/x86/crc32_impl.h → crc32_impl.h} +22 -23
- data/ext/deflate_ruby/{libdeflate/lib/crc32_multipliers.h → crc32_multipliers.h} +2 -4
- data/ext/deflate_ruby/{libdeflate/lib/x86/crc32_pclmul_template.h → crc32_pclmul_template.h} +23 -94
- data/ext/deflate_ruby/{libdeflate/lib/crc32_tables.h → crc32_tables.h} +1 -1
- data/ext/deflate_ruby/{libdeflate/lib/deflate_compress.c → deflate_compress.c} +59 -60
- data/ext/deflate_ruby/deflate_ruby.c +392 -218
- data/ext/deflate_ruby/deflate_ruby.h +6 -0
- data/ext/deflate_ruby/extconf.rb +35 -25
- data/ext/deflate_ruby/libdeflate/adler32.c +162 -0
- data/ext/deflate_ruby/libdeflate/{lib/arm → arm}/adler32_impl.h +14 -7
- data/ext/deflate_ruby/libdeflate/{lib/arm → arm}/crc32_impl.h +25 -31
- data/ext/deflate_ruby/libdeflate/arm/crc32_pmull_helpers.h +156 -0
- data/ext/deflate_ruby/libdeflate/arm/crc32_pmull_wide.h +226 -0
- data/ext/deflate_ruby/libdeflate/bt_matchfinder.h +342 -0
- data/ext/deflate_ruby/libdeflate/common_defs.h +2 -1
- data/ext/deflate_ruby/libdeflate/cpu_features_common.h +93 -0
- data/ext/deflate_ruby/libdeflate/crc32.c +262 -0
- data/ext/deflate_ruby/libdeflate/crc32_multipliers.h +375 -0
- data/ext/deflate_ruby/libdeflate/crc32_tables.h +587 -0
- data/ext/deflate_ruby/libdeflate/decompress_template.h +777 -0
- data/ext/deflate_ruby/libdeflate/deflate_compress.c +4128 -0
- data/ext/deflate_ruby/libdeflate/deflate_compress.h +15 -0
- data/ext/deflate_ruby/libdeflate/deflate_constants.h +56 -0
- data/ext/deflate_ruby/libdeflate/deflate_decompress.c +1208 -0
- data/ext/deflate_ruby/libdeflate/gzip_compress.c +90 -0
- data/ext/deflate_ruby/libdeflate/gzip_constants.h +45 -0
- data/ext/deflate_ruby/libdeflate/gzip_decompress.c +144 -0
- data/ext/deflate_ruby/libdeflate/hc_matchfinder.h +401 -0
- data/ext/deflate_ruby/libdeflate/ht_matchfinder.h +234 -0
- data/ext/deflate_ruby/libdeflate/lib_common.h +106 -0
- data/ext/deflate_ruby/libdeflate/libdeflate.h +2 -2
- data/ext/deflate_ruby/libdeflate/{lib/matchfinder_common.h → matchfinder_common.h} +3 -3
- data/ext/deflate_ruby/libdeflate/x86/adler32_impl.h +135 -0
- data/ext/deflate_ruby/libdeflate/x86/adler32_template.h +518 -0
- data/ext/deflate_ruby/libdeflate/x86/cpu_features.c +213 -0
- data/ext/deflate_ruby/libdeflate/x86/cpu_features.h +170 -0
- data/ext/deflate_ruby/libdeflate/x86/crc32_impl.h +159 -0
- data/ext/deflate_ruby/libdeflate/x86/crc32_pclmul_template.h +424 -0
- data/ext/deflate_ruby/libdeflate/x86/decompress_impl.h +57 -0
- data/ext/deflate_ruby/libdeflate.h +411 -0
- data/ext/deflate_ruby/matchfinder_common.h +224 -0
- data/ext/deflate_ruby/matchfinder_impl.h +122 -0
- data/ext/deflate_ruby/utils.c +141 -0
- data/ext/deflate_ruby/zlib_compress.c +82 -0
- data/ext/deflate_ruby/zlib_constants.h +21 -0
- data/ext/deflate_ruby/zlib_decompress.c +104 -0
- data/lib/deflate_ruby/version.rb +1 -1
- data/lib/deflate_ruby.rb +1 -63
- data/sig/deflate_ruby.rbs +4 -0
- data/test/test_deflate_ruby.rb +220 -0
- data/test/test_helper.rb +6 -0
- metadata +90 -144
- data/ext/deflate_ruby/libdeflate/CMakeLists.txt +0 -270
- data/ext/deflate_ruby/libdeflate/NEWS.md +0 -494
- data/ext/deflate_ruby/libdeflate/README.md +0 -228
- data/ext/deflate_ruby/libdeflate/libdeflate-config.cmake.in +0 -3
- data/ext/deflate_ruby/libdeflate/libdeflate.pc.in +0 -18
- data/ext/deflate_ruby/libdeflate/programs/CMakeLists.txt +0 -105
- data/ext/deflate_ruby/libdeflate/programs/benchmark.c +0 -696
- data/ext/deflate_ruby/libdeflate/programs/checksum.c +0 -218
- data/ext/deflate_ruby/libdeflate/programs/config.h.in +0 -19
- data/ext/deflate_ruby/libdeflate/programs/gzip.c +0 -688
- data/ext/deflate_ruby/libdeflate/programs/prog_util.c +0 -521
- data/ext/deflate_ruby/libdeflate/programs/prog_util.h +0 -225
- data/ext/deflate_ruby/libdeflate/programs/test_checksums.c +0 -200
- data/ext/deflate_ruby/libdeflate/programs/test_custom_malloc.c +0 -155
- data/ext/deflate_ruby/libdeflate/programs/test_incomplete_codes.c +0 -385
- data/ext/deflate_ruby/libdeflate/programs/test_invalid_streams.c +0 -130
- data/ext/deflate_ruby/libdeflate/programs/test_litrunlen_overflow.c +0 -72
- data/ext/deflate_ruby/libdeflate/programs/test_overread.c +0 -95
- data/ext/deflate_ruby/libdeflate/programs/test_slow_decompression.c +0 -472
- data/ext/deflate_ruby/libdeflate/programs/test_trailing_bytes.c +0 -151
- data/ext/deflate_ruby/libdeflate/programs/test_util.c +0 -237
- data/ext/deflate_ruby/libdeflate/programs/test_util.h +0 -61
- data/ext/deflate_ruby/libdeflate/programs/tgetopt.c +0 -118
- data/ext/deflate_ruby/libdeflate/scripts/android_build.sh +0 -118
- data/ext/deflate_ruby/libdeflate/scripts/android_tests.sh +0 -69
- data/ext/deflate_ruby/libdeflate/scripts/benchmark.sh +0 -10
- data/ext/deflate_ruby/libdeflate/scripts/checksum.sh +0 -10
- data/ext/deflate_ruby/libdeflate/scripts/checksum_benchmarks.sh +0 -253
- data/ext/deflate_ruby/libdeflate/scripts/cmake-helper.sh +0 -17
- data/ext/deflate_ruby/libdeflate/scripts/deflate_benchmarks.sh +0 -119
- data/ext/deflate_ruby/libdeflate/scripts/exec_tests.sh +0 -38
- data/ext/deflate_ruby/libdeflate/scripts/gen-release-archives.sh +0 -37
- data/ext/deflate_ruby/libdeflate/scripts/gen_bitreverse_tab.py +0 -19
- data/ext/deflate_ruby/libdeflate/scripts/gen_crc32_multipliers.c +0 -199
- data/ext/deflate_ruby/libdeflate/scripts/gen_crc32_tables.c +0 -105
- data/ext/deflate_ruby/libdeflate/scripts/gen_default_litlen_costs.py +0 -44
- data/ext/deflate_ruby/libdeflate/scripts/gen_offset_slot_map.py +0 -29
- data/ext/deflate_ruby/libdeflate/scripts/gzip_tests.sh +0 -523
- data/ext/deflate_ruby/libdeflate/scripts/libFuzzer/deflate_compress/corpus/0 +0 -0
- data/ext/deflate_ruby/libdeflate/scripts/libFuzzer/deflate_compress/fuzz.c +0 -95
- data/ext/deflate_ruby/libdeflate/scripts/libFuzzer/deflate_decompress/corpus/0 +0 -3
- data/ext/deflate_ruby/libdeflate/scripts/libFuzzer/deflate_decompress/fuzz.c +0 -62
- data/ext/deflate_ruby/libdeflate/scripts/libFuzzer/fuzz.sh +0 -108
- data/ext/deflate_ruby/libdeflate/scripts/libFuzzer/gzip_decompress/corpus/0 +0 -0
- data/ext/deflate_ruby/libdeflate/scripts/libFuzzer/gzip_decompress/fuzz.c +0 -19
- data/ext/deflate_ruby/libdeflate/scripts/libFuzzer/zlib_decompress/corpus/0 +0 -3
- data/ext/deflate_ruby/libdeflate/scripts/libFuzzer/zlib_decompress/fuzz.c +0 -19
- data/ext/deflate_ruby/libdeflate/scripts/run_tests.sh +0 -416
- data/ext/deflate_ruby/libdeflate/scripts/toolchain-i686-w64-mingw32.cmake +0 -8
- data/ext/deflate_ruby/libdeflate/scripts/toolchain-x86_64-w64-mingw32.cmake +0 -8
- /data/ext/deflate_ruby/{libdeflate/lib/adler32.c → adler32.c} +0 -0
- /data/ext/deflate_ruby/{libdeflate/lib/x86/adler32_template.h → adler32_template.h} +0 -0
- /data/ext/deflate_ruby/{libdeflate/lib/bt_matchfinder.h → bt_matchfinder.h} +0 -0
- /data/ext/deflate_ruby/{libdeflate/lib/cpu_features_common.h → cpu_features_common.h} +0 -0
- /data/ext/deflate_ruby/{libdeflate/lib/crc32.c → crc32.c} +0 -0
- /data/ext/deflate_ruby/{libdeflate/lib/arm/crc32_pmull_helpers.h → crc32_pmull_helpers.h} +0 -0
- /data/ext/deflate_ruby/{libdeflate/lib/arm/crc32_pmull_wide.h → crc32_pmull_wide.h} +0 -0
- /data/ext/deflate_ruby/{libdeflate/lib/x86/decompress_impl.h → decompress_impl.h} +0 -0
- /data/ext/deflate_ruby/{libdeflate/lib/decompress_template.h → decompress_template.h} +0 -0
- /data/ext/deflate_ruby/{libdeflate/lib/deflate_compress.h → deflate_compress.h} +0 -0
- /data/ext/deflate_ruby/{libdeflate/lib/deflate_constants.h → deflate_constants.h} +0 -0
- /data/ext/deflate_ruby/{libdeflate/lib/deflate_decompress.c → deflate_decompress.c} +0 -0
- /data/ext/deflate_ruby/{libdeflate/lib/gzip_compress.c → gzip_compress.c} +0 -0
- /data/ext/deflate_ruby/{libdeflate/lib/gzip_constants.h → gzip_constants.h} +0 -0
- /data/ext/deflate_ruby/{libdeflate/lib/gzip_decompress.c → gzip_decompress.c} +0 -0
- /data/ext/deflate_ruby/{libdeflate/lib/hc_matchfinder.h → hc_matchfinder.h} +0 -0
- /data/ext/deflate_ruby/{libdeflate/lib/ht_matchfinder.h → ht_matchfinder.h} +0 -0
- /data/ext/deflate_ruby/{libdeflate/lib/lib_common.h → lib_common.h} +0 -0
- /data/ext/deflate_ruby/libdeflate/{lib/arm → arm}/cpu_features.c +0 -0
- /data/ext/deflate_ruby/libdeflate/{lib/arm → arm}/cpu_features.h +0 -0
- /data/ext/deflate_ruby/libdeflate/{lib/arm → arm}/matchfinder_impl.h +0 -0
- /data/ext/deflate_ruby/libdeflate/{lib/riscv → riscv}/matchfinder_impl.h +0 -0
- /data/ext/deflate_ruby/libdeflate/{lib/utils.c → utils.c} +0 -0
- /data/ext/deflate_ruby/libdeflate/{lib/x86 → x86}/matchfinder_impl.h +0 -0
- /data/ext/deflate_ruby/libdeflate/{lib/zlib_compress.c → zlib_compress.c} +0 -0
- /data/ext/deflate_ruby/libdeflate/{lib/zlib_constants.h → zlib_constants.h} +0 -0
- /data/ext/deflate_ruby/libdeflate/{lib/zlib_decompress.c → zlib_decompress.c} +0 -0
|
@@ -234,7 +234,7 @@ check_buildtime_parameters(void)
|
|
|
234
234
|
/******************************************************************************/
|
|
235
235
|
|
|
236
236
|
/* Table: length slot => length slot base value */
|
|
237
|
-
static const
|
|
237
|
+
static const u32 deflate_length_slot_base[] = {
|
|
238
238
|
3, 4, 5, 6, 7, 8, 9, 10,
|
|
239
239
|
11, 13, 15, 17, 19, 23, 27, 31,
|
|
240
240
|
35, 43, 51, 59, 67, 83, 99, 115,
|
|
@@ -250,7 +250,7 @@ static const u8 deflate_extra_length_bits[] = {
|
|
|
250
250
|
};
|
|
251
251
|
|
|
252
252
|
/* Table: offset slot => offset slot base value */
|
|
253
|
-
static const
|
|
253
|
+
static const u32 deflate_offset_slot_base[] = {
|
|
254
254
|
1, 2, 3, 4, 5, 7, 9, 13,
|
|
255
255
|
17, 25, 33, 49, 65, 97, 129, 193,
|
|
256
256
|
257, 385, 513, 769, 1025, 1537, 2049, 3073,
|
|
@@ -470,13 +470,13 @@ struct libdeflate_compressor {
|
|
|
470
470
|
* The maximum search depth: consider at most this many potential
|
|
471
471
|
* matches at each position
|
|
472
472
|
*/
|
|
473
|
-
|
|
473
|
+
u32 max_search_depth;
|
|
474
474
|
|
|
475
475
|
/*
|
|
476
476
|
* The "nice" match length: if a match of this length is found, choose
|
|
477
477
|
* it immediately without further consideration
|
|
478
478
|
*/
|
|
479
|
-
|
|
479
|
+
u32 nice_match_length;
|
|
480
480
|
|
|
481
481
|
/* Frequency counters for the current block */
|
|
482
482
|
struct deflate_freqs freqs;
|
|
@@ -626,7 +626,7 @@ struct libdeflate_compressor {
|
|
|
626
626
|
* early, before max_optim_passes has been reached.
|
|
627
627
|
* Smaller values = more compression.
|
|
628
628
|
*/
|
|
629
|
-
|
|
629
|
+
u32 min_improvement_to_continue;
|
|
630
630
|
|
|
631
631
|
/*
|
|
632
632
|
* The minimum number of bits that would need to be
|
|
@@ -636,7 +636,7 @@ struct libdeflate_compressor {
|
|
|
636
636
|
* optimization pass actually increased the cost.
|
|
637
637
|
* Smaller values = more compression.
|
|
638
638
|
*/
|
|
639
|
-
|
|
639
|
+
u32 min_bits_to_use_nonfinal_path;
|
|
640
640
|
|
|
641
641
|
/*
|
|
642
642
|
* The maximum block length, in uncompressed bytes, at
|
|
@@ -653,7 +653,7 @@ struct libdeflate_compressor {
|
|
|
653
653
|
* match/literal list as the optimized dynamic block
|
|
654
654
|
* happens to be cheaper than the dynamic block itself.
|
|
655
655
|
*/
|
|
656
|
-
|
|
656
|
+
u32 max_len_to_optimize_static_block;
|
|
657
657
|
|
|
658
658
|
} n; /* (n)ear-optimal */
|
|
659
659
|
#endif /* SUPPORT_NEAR_OPTIMAL_PARSING */
|
|
@@ -1639,7 +1639,7 @@ static void
|
|
|
1639
1639
|
deflate_compute_full_len_codewords(struct libdeflate_compressor *c,
|
|
1640
1640
|
const struct deflate_codes *codes)
|
|
1641
1641
|
{
|
|
1642
|
-
|
|
1642
|
+
u32 len;
|
|
1643
1643
|
|
|
1644
1644
|
STATIC_ASSERT(MAX_LITLEN_CODEWORD_LEN +
|
|
1645
1645
|
DEFLATE_MAX_EXTRA_LENGTH_BITS <= 32);
|
|
@@ -1662,8 +1662,8 @@ deflate_compute_full_len_codewords(struct libdeflate_compressor *c,
|
|
|
1662
1662
|
do { \
|
|
1663
1663
|
const struct libdeflate_compressor *c__ = (c_); \
|
|
1664
1664
|
const struct deflate_codes *codes__ = (codes_); \
|
|
1665
|
-
|
|
1666
|
-
|
|
1665
|
+
u32 length__ = (length_); \
|
|
1666
|
+
u32 offset__ = (offset_); \
|
|
1667
1667
|
unsigned offset_slot__ = (offset_slot_); \
|
|
1668
1668
|
\
|
|
1669
1669
|
/* Litlen symbol and extra length bits */ \
|
|
@@ -1936,9 +1936,9 @@ deflate_flush_block(struct libdeflate_compressor *c,
|
|
|
1936
1936
|
struct deflate_optimum_node * const end_node =
|
|
1937
1937
|
&c->p.n.optimum_nodes[block_length];
|
|
1938
1938
|
do {
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1939
|
+
u32 length = cur_node->item & OPTIMUM_LEN_MASK;
|
|
1940
|
+
u32 offset = cur_node->item >> OPTIMUM_OFFSET_SHIFT;
|
|
1941
|
+
|
|
1942
1942
|
if (length == 1) {
|
|
1943
1943
|
/* Literal */
|
|
1944
1944
|
ADD_BITS(codes->codewords.litlen[offset],
|
|
@@ -1960,8 +1960,8 @@ deflate_flush_block(struct libdeflate_compressor *c,
|
|
|
1960
1960
|
for (seq = sequences; ; seq++) {
|
|
1961
1961
|
u32 litrunlen = seq->litrunlen_and_length &
|
|
1962
1962
|
SEQ_LITRUNLEN_MASK;
|
|
1963
|
-
|
|
1964
|
-
|
|
1963
|
+
u32 length = seq->litrunlen_and_length >>
|
|
1964
|
+
SEQ_LENGTH_SHIFT;
|
|
1965
1965
|
unsigned lit;
|
|
1966
1966
|
|
|
1967
1967
|
/* Output a run of literals. */
|
|
@@ -2118,7 +2118,7 @@ observe_literal(struct block_split_stats *stats, u8 lit)
|
|
|
2118
2118
|
* one observation type for "long match".
|
|
2119
2119
|
*/
|
|
2120
2120
|
static forceinline void
|
|
2121
|
-
observe_match(struct block_split_stats *stats,
|
|
2121
|
+
observe_match(struct block_split_stats *stats, u32 length)
|
|
2122
2122
|
{
|
|
2123
2123
|
stats->new_observations[NUM_LITERAL_OBSERVATION_TYPES +
|
|
2124
2124
|
(length >= 9)]++;
|
|
@@ -2242,7 +2242,7 @@ deflate_choose_literal(struct libdeflate_compressor *c, unsigned literal,
|
|
|
2242
2242
|
|
|
2243
2243
|
static forceinline void
|
|
2244
2244
|
deflate_choose_match(struct libdeflate_compressor *c,
|
|
2245
|
-
|
|
2245
|
+
u32 length, u32 offset, bool gather_split_stats,
|
|
2246
2246
|
struct deflate_sequence **seq_p)
|
|
2247
2247
|
{
|
|
2248
2248
|
struct deflate_sequence *seq = *seq_p;
|
|
@@ -2254,7 +2254,7 @@ deflate_choose_match(struct libdeflate_compressor *c,
|
|
|
2254
2254
|
if (gather_split_stats)
|
|
2255
2255
|
observe_match(&c->split_stats, length);
|
|
2256
2256
|
|
|
2257
|
-
seq->litrunlen_and_length |=
|
|
2257
|
+
seq->litrunlen_and_length |= length << SEQ_LENGTH_SHIFT;
|
|
2258
2258
|
seq->offset = offset;
|
|
2259
2259
|
seq->offset_slot = offset_slot;
|
|
2260
2260
|
|
|
@@ -2268,7 +2268,7 @@ deflate_choose_match(struct libdeflate_compressor *c,
|
|
|
2268
2268
|
* the input buffer.
|
|
2269
2269
|
*/
|
|
2270
2270
|
static forceinline void
|
|
2271
|
-
adjust_max_and_nice_len(
|
|
2271
|
+
adjust_max_and_nice_len(u32 *max_len, u32 *nice_len, size_t remaining)
|
|
2272
2272
|
{
|
|
2273
2273
|
if (unlikely(remaining < DEFLATE_MAX_MATCH_LEN)) {
|
|
2274
2274
|
*max_len = remaining;
|
|
@@ -2292,8 +2292,8 @@ adjust_max_and_nice_len(unsigned *max_len, unsigned *nice_len, size_t remaining)
|
|
|
2292
2292
|
* probably be worthwhile. Conversely, if not many literals are used, then
|
|
2293
2293
|
* probably literals will be cheap and short matches won't be worthwhile.
|
|
2294
2294
|
*/
|
|
2295
|
-
static
|
|
2296
|
-
choose_min_match_len(
|
|
2295
|
+
static u32
|
|
2296
|
+
choose_min_match_len(u32 num_used_literals, u32 max_search_depth)
|
|
2297
2297
|
{
|
|
2298
2298
|
/* map from num_used_literals to min_len */
|
|
2299
2299
|
static const u8 min_lens[] = {
|
|
@@ -2304,7 +2304,7 @@ choose_min_match_len(unsigned num_used_literals, unsigned max_search_depth)
|
|
|
2304
2304
|
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
|
2305
2305
|
/* The rest is implicitly 3. */
|
|
2306
2306
|
};
|
|
2307
|
-
|
|
2307
|
+
u32 min_len;
|
|
2308
2308
|
|
|
2309
2309
|
STATIC_ASSERT(DEFLATE_MIN_MATCH_LEN <= 3);
|
|
2310
2310
|
STATIC_ASSERT(ARRAY_LEN(min_lens) <= DEFLATE_NUM_LITERALS + 1);
|
|
@@ -2326,12 +2326,11 @@ choose_min_match_len(unsigned num_used_literals, unsigned max_search_depth)
|
|
|
2326
2326
|
return min_len;
|
|
2327
2327
|
}
|
|
2328
2328
|
|
|
2329
|
-
static
|
|
2330
|
-
calculate_min_match_len(const u8 *data, size_t data_len,
|
|
2331
|
-
unsigned max_search_depth)
|
|
2329
|
+
static u32
|
|
2330
|
+
calculate_min_match_len(const u8 *data, size_t data_len, u32 max_search_depth)
|
|
2332
2331
|
{
|
|
2333
2332
|
u8 used[256] = { 0 };
|
|
2334
|
-
|
|
2333
|
+
u32 num_used_literals = 0;
|
|
2335
2334
|
size_t i;
|
|
2336
2335
|
|
|
2337
2336
|
/*
|
|
@@ -2357,13 +2356,13 @@ calculate_min_match_len(const u8 *data, size_t data_len,
|
|
|
2357
2356
|
* Recalculate the minimum match length for a block, now that we know the
|
|
2358
2357
|
* distribution of literals that are actually being used (freqs->litlen).
|
|
2359
2358
|
*/
|
|
2360
|
-
static
|
|
2359
|
+
static u32
|
|
2361
2360
|
recalculate_min_match_len(const struct deflate_freqs *freqs,
|
|
2362
|
-
|
|
2361
|
+
u32 max_search_depth)
|
|
2363
2362
|
{
|
|
2364
2363
|
u32 literal_freq = 0;
|
|
2365
2364
|
u32 cutoff;
|
|
2366
|
-
|
|
2365
|
+
u32 num_used_literals = 0;
|
|
2367
2366
|
int i;
|
|
2368
2367
|
|
|
2369
2368
|
for (i = 0; i < DEFLATE_NUM_LITERALS; i++)
|
|
@@ -2457,8 +2456,8 @@ deflate_compress_fastest(struct libdeflate_compressor * restrict c,
|
|
|
2457
2456
|
const u8 *in_next = in;
|
|
2458
2457
|
const u8 *in_end = in_next + in_nbytes;
|
|
2459
2458
|
const u8 *in_cur_base = in_next;
|
|
2460
|
-
|
|
2461
|
-
|
|
2459
|
+
u32 max_len = DEFLATE_MAX_MATCH_LEN;
|
|
2460
|
+
u32 nice_len = MIN(c->nice_match_length, max_len);
|
|
2462
2461
|
u32 next_hash = 0;
|
|
2463
2462
|
|
|
2464
2463
|
ht_matchfinder_init(&c->p.f.ht_mf);
|
|
@@ -2534,8 +2533,8 @@ deflate_compress_greedy(struct libdeflate_compressor * restrict c,
|
|
|
2534
2533
|
const u8 *in_next = in;
|
|
2535
2534
|
const u8 *in_end = in_next + in_nbytes;
|
|
2536
2535
|
const u8 *in_cur_base = in_next;
|
|
2537
|
-
|
|
2538
|
-
|
|
2536
|
+
u32 max_len = DEFLATE_MAX_MATCH_LEN;
|
|
2537
|
+
u32 nice_len = MIN(c->nice_match_length, max_len);
|
|
2539
2538
|
u32 next_hashes[2] = {0, 0};
|
|
2540
2539
|
|
|
2541
2540
|
hc_matchfinder_init(&c->p.g.hc_mf);
|
|
@@ -2547,7 +2546,7 @@ deflate_compress_greedy(struct libdeflate_compressor * restrict c,
|
|
|
2547
2546
|
const u8 * const in_max_block_end = choose_max_block_end(
|
|
2548
2547
|
in_next, in_end, SOFT_MAX_BLOCK_LENGTH);
|
|
2549
2548
|
struct deflate_sequence *seq = c->p.g.sequences;
|
|
2550
|
-
|
|
2549
|
+
u32 min_len;
|
|
2551
2550
|
|
|
2552
2551
|
init_block_split_stats(&c->split_stats);
|
|
2553
2552
|
deflate_begin_sequences(c, seq);
|
|
@@ -2610,8 +2609,8 @@ deflate_compress_lazy_generic(struct libdeflate_compressor * restrict c,
|
|
|
2610
2609
|
const u8 *in_next = in;
|
|
2611
2610
|
const u8 *in_end = in_next + in_nbytes;
|
|
2612
2611
|
const u8 *in_cur_base = in_next;
|
|
2613
|
-
|
|
2614
|
-
|
|
2612
|
+
u32 max_len = DEFLATE_MAX_MATCH_LEN;
|
|
2613
|
+
u32 nice_len = MIN(c->nice_match_length, max_len);
|
|
2615
2614
|
u32 next_hashes[2] = {0, 0};
|
|
2616
2615
|
|
|
2617
2616
|
hc_matchfinder_init(&c->p.g.hc_mf);
|
|
@@ -2625,7 +2624,7 @@ deflate_compress_lazy_generic(struct libdeflate_compressor * restrict c,
|
|
|
2625
2624
|
const u8 *next_recalc_min_len =
|
|
2626
2625
|
in_next + MIN(in_end - in_next, 10000);
|
|
2627
2626
|
struct deflate_sequence *seq = c->p.g.sequences;
|
|
2628
|
-
|
|
2627
|
+
u32 min_len;
|
|
2629
2628
|
|
|
2630
2629
|
init_block_split_stats(&c->split_stats);
|
|
2631
2630
|
deflate_begin_sequences(c, seq);
|
|
@@ -2633,10 +2632,10 @@ deflate_compress_lazy_generic(struct libdeflate_compressor * restrict c,
|
|
|
2633
2632
|
in_max_block_end - in_next,
|
|
2634
2633
|
c->max_search_depth);
|
|
2635
2634
|
do {
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2635
|
+
u32 cur_len;
|
|
2636
|
+
u32 cur_offset;
|
|
2637
|
+
u32 next_len;
|
|
2638
|
+
u32 next_offset;
|
|
2640
2639
|
|
|
2641
2640
|
/*
|
|
2642
2641
|
* Recalculate the minimum match length if it hasn't
|
|
@@ -2849,8 +2848,8 @@ deflate_tally_item_list(struct libdeflate_compressor *c, u32 block_length)
|
|
|
2849
2848
|
&c->p.n.optimum_nodes[block_length];
|
|
2850
2849
|
|
|
2851
2850
|
do {
|
|
2852
|
-
|
|
2853
|
-
|
|
2851
|
+
u32 length = cur_node->item & OPTIMUM_LEN_MASK;
|
|
2852
|
+
u32 offset = cur_node->item >> OPTIMUM_OFFSET_SHIFT;
|
|
2854
2853
|
|
|
2855
2854
|
if (length == 1) {
|
|
2856
2855
|
/* Literal */
|
|
@@ -3111,7 +3110,7 @@ deflate_choose_default_litlen_costs(struct libdeflate_compressor *c,
|
|
|
3111
3110
|
const u8 *block_begin, u32 block_length,
|
|
3112
3111
|
u32 *lit_cost, u32 *len_sym_cost)
|
|
3113
3112
|
{
|
|
3114
|
-
|
|
3113
|
+
u32 num_used_literals = 0;
|
|
3115
3114
|
u32 literal_freq = block_length;
|
|
3116
3115
|
u32 match_freq = 0;
|
|
3117
3116
|
u32 cutoff;
|
|
@@ -3161,7 +3160,7 @@ deflate_choose_default_litlen_costs(struct libdeflate_compressor *c,
|
|
|
3161
3160
|
}
|
|
3162
3161
|
|
|
3163
3162
|
static forceinline u32
|
|
3164
|
-
deflate_default_length_cost(
|
|
3163
|
+
deflate_default_length_cost(u32 len, u32 len_sym_cost)
|
|
3165
3164
|
{
|
|
3166
3165
|
unsigned slot = deflate_length_slot[len];
|
|
3167
3166
|
u32 num_extra_bits = deflate_extra_length_bits[slot];
|
|
@@ -3188,7 +3187,7 @@ static void
|
|
|
3188
3187
|
deflate_set_default_costs(struct libdeflate_compressor *c,
|
|
3189
3188
|
u32 lit_cost, u32 len_sym_cost)
|
|
3190
3189
|
{
|
|
3191
|
-
|
|
3190
|
+
u32 i;
|
|
3192
3191
|
|
|
3193
3192
|
/* Literals */
|
|
3194
3193
|
for (i = 0; i < DEFLATE_NUM_LITERALS; i++)
|
|
@@ -3224,7 +3223,7 @@ static forceinline void
|
|
|
3224
3223
|
deflate_adjust_costs_impl(struct libdeflate_compressor *c,
|
|
3225
3224
|
u32 lit_cost, u32 len_sym_cost, int change_amount)
|
|
3226
3225
|
{
|
|
3227
|
-
|
|
3226
|
+
u32 i;
|
|
3228
3227
|
|
|
3229
3228
|
/* Literals */
|
|
3230
3229
|
for (i = 0; i < DEFLATE_NUM_LITERALS; i++)
|
|
@@ -3337,7 +3336,7 @@ deflate_find_min_cost_path(struct libdeflate_compressor *c,
|
|
|
3337
3336
|
cur_node->cost_to_end = 0;
|
|
3338
3337
|
do {
|
|
3339
3338
|
unsigned num_matches;
|
|
3340
|
-
|
|
3339
|
+
u32 literal;
|
|
3341
3340
|
u32 best_cost_to_end;
|
|
3342
3341
|
|
|
3343
3342
|
cur_node--;
|
|
@@ -3349,14 +3348,14 @@ deflate_find_min_cost_path(struct libdeflate_compressor *c,
|
|
|
3349
3348
|
/* It's always possible to choose a literal. */
|
|
3350
3349
|
best_cost_to_end = c->p.n.costs.literal[literal] +
|
|
3351
3350
|
(cur_node + 1)->cost_to_end;
|
|
3352
|
-
cur_node->item = (
|
|
3351
|
+
cur_node->item = (literal << OPTIMUM_OFFSET_SHIFT) | 1;
|
|
3353
3352
|
|
|
3354
3353
|
/* Also consider matches if there are any. */
|
|
3355
3354
|
if (num_matches) {
|
|
3356
3355
|
const struct lz_match *match;
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3356
|
+
u32 len;
|
|
3357
|
+
u32 offset;
|
|
3358
|
+
u32 offset_slot;
|
|
3360
3359
|
u32 offset_cost;
|
|
3361
3360
|
u32 cost_to_end;
|
|
3362
3361
|
|
|
@@ -3384,7 +3383,7 @@ deflate_find_min_cost_path(struct libdeflate_compressor *c,
|
|
|
3384
3383
|
if (cost_to_end < best_cost_to_end) {
|
|
3385
3384
|
best_cost_to_end = cost_to_end;
|
|
3386
3385
|
cur_node->item = len |
|
|
3387
|
-
(
|
|
3386
|
+
(offset <<
|
|
3388
3387
|
OPTIMUM_OFFSET_SHIFT);
|
|
3389
3388
|
}
|
|
3390
3389
|
} while (++len <= match->length);
|
|
@@ -3601,8 +3600,8 @@ deflate_compress_near_optimal(struct libdeflate_compressor * restrict c,
|
|
|
3601
3600
|
const u8 *in_cur_base = in_next;
|
|
3602
3601
|
const u8 *in_next_slide =
|
|
3603
3602
|
in_next + MIN(in_end - in_next, MATCHFINDER_WINDOW_SIZE);
|
|
3604
|
-
|
|
3605
|
-
|
|
3603
|
+
u32 max_len = DEFLATE_MAX_MATCH_LEN;
|
|
3604
|
+
u32 nice_len = MIN(c->nice_match_length, max_len);
|
|
3606
3605
|
struct lz_match *cache_ptr = c->p.n.match_cache;
|
|
3607
3606
|
u32 next_hashes[2] = {0, 0};
|
|
3608
3607
|
bool prev_block_used_only_literals = false;
|
|
@@ -3617,7 +3616,7 @@ deflate_compress_near_optimal(struct libdeflate_compressor * restrict c,
|
|
|
3617
3616
|
const u8 *prev_end_block_check = NULL;
|
|
3618
3617
|
bool change_detected = false;
|
|
3619
3618
|
const u8 *next_observation = in_next;
|
|
3620
|
-
|
|
3619
|
+
u32 min_len;
|
|
3621
3620
|
|
|
3622
3621
|
/*
|
|
3623
3622
|
* Use the minimum match length heuristic to improve the
|
|
@@ -3648,7 +3647,7 @@ deflate_compress_near_optimal(struct libdeflate_compressor * restrict c,
|
|
|
3648
3647
|
*/
|
|
3649
3648
|
for (;;) {
|
|
3650
3649
|
struct lz_match *matches;
|
|
3651
|
-
|
|
3650
|
+
u32 best_len;
|
|
3652
3651
|
size_t remaining = in_end - in_next;
|
|
3653
3652
|
|
|
3654
3653
|
/* Slide the window forward if needed. */
|
|
@@ -3853,9 +3852,9 @@ deflate_compress_near_optimal(struct libdeflate_compressor * restrict c,
|
|
|
3853
3852
|
static void
|
|
3854
3853
|
deflate_init_offset_slot_full(struct libdeflate_compressor *c)
|
|
3855
3854
|
{
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3855
|
+
u32 offset_slot;
|
|
3856
|
+
u32 offset;
|
|
3857
|
+
u32 offset_end;
|
|
3859
3858
|
|
|
3860
3859
|
for (offset_slot = 0; offset_slot < ARRAY_LEN(deflate_offset_slot_base);
|
|
3861
3860
|
offset_slot++) {
|