aboutsummaryrefslogtreecommitdiff
path: root/src/liblzma/lzma
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2008-09-27 19:09:21 +0300
committerLasse Collin <lasse.collin@tukaani.org>2008-09-27 19:09:21 +0300
commit1dcecfb09b55157b8653d747963069c8bed74f04 (patch)
tree81fa1f1e8bf6871981970ca826d897db6f33527b /src/liblzma/lzma
parentAdded 7z2lzma.bash. (diff)
downloadxz-1dcecfb09b55157b8653d747963069c8bed74f04.tar.xz
Some API changes, bug fixes, cleanups etc.
Diffstat (limited to '')
-rw-r--r--src/liblzma/lzma/Makefile.am4
-rw-r--r--src/liblzma/lzma/lzma2_decoder.c10
-rw-r--r--src/liblzma/lzma/lzma2_encoder.c27
-rw-r--r--src/liblzma/lzma/lzma_common.h26
-rw-r--r--src/liblzma/lzma/lzma_decoder.c37
-rw-r--r--src/liblzma/lzma/lzma_encoder.c51
-rw-r--r--src/liblzma/lzma/lzma_encoder_optimum_fast.c10
-rw-r--r--src/liblzma/lzma/lzma_encoder_optimum_normal.c20
-rw-r--r--src/liblzma/lzma/lzma_encoder_presets.c50
9 files changed, 112 insertions, 123 deletions
diff --git a/src/liblzma/lzma/Makefile.am b/src/liblzma/lzma/Makefile.am
index bcc1fdc6..ec6b7b27 100644
--- a/src/liblzma/lzma/Makefile.am
+++ b/src/liblzma/lzma/Makefile.am
@@ -24,7 +24,7 @@ liblzma2_la_CPPFLAGS = \
liblzma2_la_SOURCES = lzma_common.h
-if COND_ENCODER_LZMA
+if COND_ENCODER_LZMA1
liblzma2_la_SOURCES += \
fastpos.h \
lzma_encoder.h \
@@ -39,7 +39,7 @@ liblzma2_la_SOURCES += fastpos_table.c
endif
endif
-if COND_DECODER_LZMA
+if COND_DECODER_LZMA1
liblzma2_la_SOURCES += \
lzma_decoder.c \
lzma_decoder.h
diff --git a/src/liblzma/lzma/lzma2_decoder.c b/src/liblzma/lzma/lzma2_decoder.c
index 88e73fb6..af1da746 100644
--- a/src/liblzma/lzma/lzma2_decoder.c
+++ b/src/liblzma/lzma/lzma2_decoder.c
@@ -303,14 +303,14 @@ lzma_lzma2_props_decode(void **options, lzma_allocator *allocator,
return LZMA_MEM_ERROR;
if (props[0] == 40) {
- opt->dictionary_size = UINT32_MAX;
+ opt->dict_size = UINT32_MAX;
} else {
- opt->dictionary_size = 2 | (props[0] & 1);
- opt->dictionary_size <<= props[0] / 2 + 11;
+ opt->dict_size = 2 | (props[0] & 1);
+ opt->dict_size <<= props[0] / 2 + 11;
}
- opt->preset_dictionary = NULL;
- opt->preset_dictionary_size = 0;
+ opt->preset_dict = NULL;
+ opt->preset_dict_size = 0;
*options = opt;
diff --git a/src/liblzma/lzma/lzma2_encoder.c b/src/liblzma/lzma/lzma2_encoder.c
index b2cd176b..757b871d 100644
--- a/src/liblzma/lzma/lzma2_encoder.c
+++ b/src/liblzma/lzma/lzma2_encoder.c
@@ -178,19 +178,13 @@ lzma2_encode(lzma_coder *restrict coder, lzma_mf *restrict mf,
// Look if there are new options. At least for now,
// only lc/lp/pb can be changed.
if (coder->opt_new != NULL
- && (coder->opt_cur.literal_context_bits
- != coder->opt_new->literal_context_bits
- || coder->opt_cur.literal_pos_bits
- != coder->opt_new->literal_pos_bits
- || coder->opt_cur.pos_bits
- != coder->opt_new->pos_bits)) {
+ && (coder->opt_cur.lc != coder->opt_new->lc
+ || coder->opt_cur.lp != coder->opt_new->lp
+ || coder->opt_cur.pb != coder->opt_new->pb)) {
// Options have been changed, copy them to opt_cur.
- coder->opt_cur.literal_context_bits
- = coder->opt_new->literal_context_bits;
- coder->opt_cur.literal_pos_bits
- = coder->opt_new->literal_pos_bits;
- coder->opt_cur.pos_bits
- = coder->opt_new->pos_bits;
+ coder->opt_cur.lc = coder->opt_new->lc;
+ coder->opt_cur.lp = coder->opt_new->lp;
+ coder->opt_cur.pb = coder->opt_new->pb;
// We need to write the new options and reset
// the encoder state.
@@ -352,10 +346,9 @@ lzma2_encoder_init(lzma_lz_encoder *lz, lzma_allocator *allocator,
// compressed size of a chunk is not smaller than the uncompressed
// size, so we need to have at least LZMA2_COMPRESSED_MAX bytes
// history available.
- if (lz_options->before_size + lz_options->dictionary_size
- < LZMA2_CHUNK_MAX)
- lz_options->before_size = LZMA2_CHUNK_MAX
- - lz_options->dictionary_size;
+ if (lz_options->before_size + lz_options->dict_size < LZMA2_CHUNK_MAX)
+ lz_options->before_size
+ = LZMA2_CHUNK_MAX - lz_options->dict_size;
return LZMA_OK;
}
@@ -385,7 +378,7 @@ extern lzma_ret
lzma_lzma2_props_encode(const void *options, uint8_t *out)
{
const lzma_options_lzma *const opt = options;
- uint32_t d = MAX(opt->dictionary_size, LZMA_DICTIONARY_SIZE_MIN);
+ uint32_t d = MAX(opt->dict_size, LZMA_DICT_SIZE_MIN);
// Round up to to the next 2^n - 1 or 2^n + 2^(n - 1) - 1 depending
// on which one is the next:
diff --git a/src/liblzma/lzma/lzma_common.h b/src/liblzma/lzma/lzma_common.h
index 6909969b..546bf89e 100644
--- a/src/liblzma/lzma/lzma_common.h
+++ b/src/liblzma/lzma/lzma_common.h
@@ -32,20 +32,16 @@
/// Maximum number of position states. A position state is the lowest pos bits
/// number of bits of the current uncompressed offset. In some places there
/// are different sets of probabilities for different pos states.
-#define POS_STATES_MAX (1 << LZMA_POS_BITS_MAX)
+#define POS_STATES_MAX (1 << LZMA_PB_MAX)
-/// Validates literal_context_bits, literal_pos_bits, and pos_bits.
+/// Validates lc, lp, and pb.
static inline bool
is_lclppb_valid(const lzma_options_lzma *options)
{
- return options->literal_context_bits <= LZMA_LITERAL_CONTEXT_BITS_MAX
- && options->literal_pos_bits
- <= LZMA_LITERAL_POS_BITS_MAX
- && options->literal_context_bits
- + options->literal_pos_bits
- <= LZMA_LITERAL_BITS_MAX
- && options->pos_bits <= LZMA_POS_BITS_MAX;
+ return options->lc <= LZMA_LCLP_MAX && options->lp <= LZMA_LCLP_MAX
+ && options->lc + options->lp <= LZMA_LCLP_MAX
+ && options->pb <= LZMA_PB_MAX;
}
@@ -126,7 +122,7 @@ typedef enum {
#define LITERAL_CODER_SIZE 0x300
/// Maximum number of literal coders
-#define LITERAL_CODERS_MAX (1 << LZMA_LITERAL_BITS_MAX)
+#define LITERAL_CODERS_MAX (1 << LZMA_LCLP_MAX)
/// Locate the literal coder for the next literal byte. The choice depends on
/// - the lowest literal_pos_bits bits of the position of the current
@@ -138,13 +134,11 @@ typedef enum {
static inline void
literal_init(probability (*probs)[LITERAL_CODER_SIZE],
- uint32_t literal_context_bits, uint32_t literal_pos_bits)
+ uint32_t lc, uint32_t lp)
{
- assert(literal_context_bits + literal_pos_bits
- <= LZMA_LITERAL_BITS_MAX);
+ assert(lc + lp <= LZMA_LCLP_MAX);
- const uint32_t coders
- = 1U << (literal_context_bits + literal_pos_bits);
+ const uint32_t coders = 1U << (lc + lp);
for (uint32_t i = 0; i < coders; ++i)
for (uint32_t j = 0; j < LITERAL_CODER_SIZE; ++j)
@@ -219,7 +213,7 @@ literal_init(probability (*probs)[LITERAL_CODER_SIZE],
// fastpos.h to understand why).
#define END_POS_MODEL_INDEX 14
-// Seven-bit distances use the full FIXME
+// Pos slots that indicate a distance <= 127.
#define FULL_DISTANCES_BITS (END_POS_MODEL_INDEX / 2)
#define FULL_DISTANCES (1 << FULL_DISTANCES_BITS)
diff --git a/src/liblzma/lzma/lzma_decoder.c b/src/liblzma/lzma/lzma_decoder.c
index 0fa62c66..df3371e2 100644
--- a/src/liblzma/lzma/lzma_decoder.c
+++ b/src/liblzma/lzma/lzma_decoder.c
@@ -231,7 +231,7 @@ struct lzma_coder_s {
uint32_t rep2; ///< Distance of third latest match
uint32_t rep3; ///< Distance of fourth latest match
- uint32_t pos_mask; // (1U << pos_bits) - 1
+ uint32_t pos_mask; // (1U << pb) - 1
uint32_t literal_context_bits;
uint32_t literal_pos_mask;
@@ -866,14 +866,13 @@ lzma_decoder_reset(lzma_coder *coder, const void *opt)
// FIXME?
// Calculate pos_mask. We don't need pos_bits as is for anything.
- coder->pos_mask = (1U << options->pos_bits) - 1;
+ coder->pos_mask = (1U << options->pb) - 1;
// Initialize the literal decoder.
- literal_init(coder->literal, options->literal_context_bits,
- options->literal_pos_bits);
+ literal_init(coder->literal, options->lc, options->lp);
- coder->literal_context_bits = options->literal_context_bits;
- coder->literal_pos_mask = (1 << options->literal_pos_bits) - 1;
+ coder->literal_context_bits = options->lc;
+ coder->literal_pos_mask = (1U << options->lp) - 1;
// State
coder->state = STATE_LIT_LIT;
@@ -881,7 +880,7 @@ lzma_decoder_reset(lzma_coder *coder, const void *opt)
coder->rep1 = 0;
coder->rep2 = 0;
coder->rep3 = 0;
- coder->pos_mask = (1 << options->pos_bits) - 1;
+ coder->pos_mask = (1U << options->pb) - 1;
// Range decoder
rc_reset(coder->rc);
@@ -908,7 +907,7 @@ lzma_decoder_reset(lzma_coder *coder, const void *opt)
bittree_reset(coder->pos_align, ALIGN_BITS);
// Len decoders (also bit/bittree)
- const uint32_t num_pos_states = 1 << options->pos_bits;
+ const uint32_t num_pos_states = 1U << options->pb;
bit_reset(coder->match_len_decoder.choice);
bit_reset(coder->match_len_decoder.choice2);
bit_reset(coder->rep_len_decoder.choice);
@@ -957,7 +956,7 @@ lzma_lzma_decoder_create(lzma_lz_decoder *lz, lzma_allocator *allocator,
// All dictionary sizes are OK here. LZ decoder will take care of
// the special cases.
const lzma_options_lzma *options = opt;
- *dict_size = options->dictionary_size;
+ *dict_size = options->dict_size;
return LZMA_OK;
}
@@ -1003,13 +1002,12 @@ lzma_lzma_lclppb_decode(lzma_options_lzma *options, uint8_t byte)
return true;
// See the file format specification to understand this.
- options->pos_bits = byte / (9 * 5);
- byte -= options->pos_bits * 9 * 5;
- options->literal_pos_bits = byte / 9;
- options->literal_context_bits = byte - options->literal_pos_bits * 9;
+ options->pb = byte / (9 * 5);
+ byte -= options->pb * 9 * 5;
+ options->lp = byte / 9;
+ options->lc = byte - options->lp * 9;
- return options->literal_context_bits + options->literal_pos_bits
- > LZMA_LITERAL_BITS_MAX;
+ return options->lc + options->lp > LZMA_LCLP_MAX;
}
@@ -1017,8 +1015,7 @@ extern uint64_t
lzma_lzma_decoder_memusage(const void *options)
{
const lzma_options_lzma *const opt = options;
- const uint64_t lz_memusage
- = lzma_lz_decoder_memusage(opt->dictionary_size);
+ const uint64_t lz_memusage = lzma_lz_decoder_memusage(opt->dict_size);
if (lz_memusage == UINT64_MAX)
return UINT64_MAX;
@@ -1044,10 +1041,10 @@ lzma_lzma_props_decode(void **options, lzma_allocator *allocator,
// All dictionary sizes are accepted, including zero. LZ decoder
// will automatically use a dictionary at least a few KiB even if
// a smaller dictionary is requested.
- opt->dictionary_size = integer_read_32(props + 1);
+ opt->dict_size = integer_read_32(props + 1);
- opt->preset_dictionary = NULL;
- opt->preset_dictionary_size = 0;
+ opt->preset_dict = NULL;
+ opt->preset_dict_size = 0;
*options = opt;
diff --git a/src/liblzma/lzma/lzma_encoder.c b/src/liblzma/lzma/lzma_encoder.c
index 02b7d19a..2f81bedc 100644
--- a/src/liblzma/lzma/lzma_encoder.c
+++ b/src/liblzma/lzma/lzma_encoder.c
@@ -428,14 +428,14 @@ set_lz_options(lzma_lz_options *lz_options, const lzma_options_lzma *options)
// LZ encoder initialization does the validation, also when just
// calculating memory usage, so we don't need to validate here.
lz_options->before_size = OPTS;
- lz_options->dictionary_size = options->dictionary_size;
+ lz_options->dict_size = options->dict_size;
lz_options->after_size = LOOP_INPUT_MAX;
lz_options->match_len_max = MATCH_LEN_MAX;
- lz_options->find_len_max = options->fast_bytes;
- lz_options->match_finder = options->match_finder;
- lz_options->match_finder_cycles = options->match_finder_cycles;
- lz_options->preset_dictionary = options->preset_dictionary;
- lz_options->preset_dictionary_size = options->preset_dictionary_size;
+ lz_options->nice_len = options->nice_len;
+ lz_options->match_finder = options->mf;
+ lz_options->depth = options->depth;
+ lz_options->preset_dict = options->preset_dict;
+ lz_options->preset_dict_size = options->preset_dict_size;
}
@@ -467,9 +467,9 @@ lzma_lzma_encoder_reset(lzma_coder *coder, const lzma_options_lzma *options)
{
assert(!coder->is_flushed);
- coder->pos_mask = (1U << options->pos_bits) - 1;
- coder->literal_context_bits = options->literal_context_bits;
- coder->literal_pos_mask = (1U << options->literal_pos_bits) - 1;
+ coder->pos_mask = (1U << options->pb) - 1;
+ coder->literal_context_bits = options->lc;
+ coder->literal_pos_mask = (1U << options->lp) - 1;
// Range coder
rc_reset(&coder->rc);
@@ -479,8 +479,7 @@ lzma_lzma_encoder_reset(lzma_coder *coder, const lzma_options_lzma *options)
for (size_t i = 0; i < REP_DISTANCES; ++i)
coder->reps[i] = 0;
- literal_init(coder->literal, options->literal_context_bits,
- options->literal_pos_bits);
+ literal_init(coder->literal, options->lc, options->lp);
// Bit encoders
for (size_t i = 0; i < STATES; ++i) {
@@ -506,10 +505,10 @@ lzma_lzma_encoder_reset(lzma_coder *coder, const lzma_options_lzma *options)
// Length encoders
length_encoder_reset(&coder->match_len_encoder,
- 1U << options->pos_bits, coder->fast_mode);
+ 1U << options->pb, coder->fast_mode);
length_encoder_reset(&coder->rep_len_encoder,
- 1U << options->pos_bits, coder->fast_mode);
+ 1U << options->pb, coder->fast_mode);
// Price counts are incremented every time appropriate probabilities
// are changed. price counts are set to zero when the price tables
@@ -546,8 +545,8 @@ lzma_lzma_encoder_create(lzma_coder **coder_ptr, lzma_allocator *allocator,
// Validate some of the options. LZ encoder validates fast_bytes too
// but we need a valid value here earlier.
- if (!is_lclppb_valid(options) || options->fast_bytes < MATCH_LEN_MIN
- || options->fast_bytes > MATCH_LEN_MAX)
+ if (!is_lclppb_valid(options) || options->nice_len < MATCH_LEN_MIN
+ || options->nice_len > MATCH_LEN_MAX)
return LZMA_OPTIONS_ERROR;
// Set compression mode.
@@ -562,17 +561,16 @@ lzma_lzma_encoder_create(lzma_coder **coder_ptr, lzma_allocator *allocator,
// Set dist_table_size.
// Round the dictionary size up to next 2^n.
uint32_t log_size = 0;
- while ((UINT32_C(1) << log_size)
- < options->dictionary_size)
+ while ((UINT32_C(1) << log_size) < options->dict_size)
++log_size;
coder->dist_table_size = log_size * 2;
// Length encoders' price table size
coder->match_len_encoder.table_size
- = options->fast_bytes + 1 - MATCH_LEN_MIN;
+ = options->nice_len + 1 - MATCH_LEN_MIN;
coder->rep_len_encoder.table_size
- = options->fast_bytes + 1 - MATCH_LEN_MIN;
+ = options->nice_len + 1 - MATCH_LEN_MIN;
break;
}
@@ -627,24 +625,17 @@ lzma_lzma_encoder_memusage(const void *options)
extern bool
lzma_lzma_lclppb_encode(const lzma_options_lzma *options, uint8_t *byte)
{
- if (options->literal_context_bits > LZMA_LITERAL_CONTEXT_BITS_MAX
- || options->literal_pos_bits
- > LZMA_LITERAL_POS_BITS_MAX
- || options->pos_bits > LZMA_POS_BITS_MAX
- || options->literal_context_bits
- + options->literal_pos_bits
- > LZMA_LITERAL_BITS_MAX)
+ if (!is_lclppb_valid(options))
return true;
- *byte = (options->pos_bits * 5 + options->literal_pos_bits) * 9
- + options->literal_context_bits;
+ *byte = (options->pb * 5 + options->lp) * 9 + options->lc;
assert(*byte <= (4 * 5 + 4) * 9 + 8);
return false;
}
-#ifdef HAVE_ENCODER_LZMA
+#ifdef HAVE_ENCODER_LZMA1
extern lzma_ret
lzma_lzma_props_encode(const void *options, uint8_t *out)
{
@@ -653,7 +644,7 @@ lzma_lzma_props_encode(const void *options, uint8_t *out)
if (lzma_lzma_lclppb_encode(opt, out))
return LZMA_PROG_ERROR;
- integer_write_32(out + 1, opt->dictionary_size);
+ integer_write_32(out + 1, opt->dict_size);
return LZMA_OK;
}
diff --git a/src/liblzma/lzma/lzma_encoder_optimum_fast.c b/src/liblzma/lzma/lzma_encoder_optimum_fast.c
index 9da7e79e..4e8e26a2 100644
--- a/src/liblzma/lzma/lzma_encoder_optimum_fast.c
+++ b/src/liblzma/lzma/lzma_encoder_optimum_fast.c
@@ -38,7 +38,7 @@ extern void
lzma_lzma_optimum_fast(lzma_coder *restrict coder, lzma_mf *restrict mf,
uint32_t *restrict back_res, uint32_t *restrict len_res)
{
- const uint32_t fast_bytes = mf->find_len_max;
+ const uint32_t nice_len = mf->nice_len;
uint32_t len_main;
uint32_t matches_count;
@@ -79,8 +79,8 @@ lzma_lzma_optimum_fast(lzma_coder *restrict coder, lzma_mf *restrict mf,
&& buf[len] == buf_back[len]; ++len) ;
// If we have found a repeated match that is at least
- // fast_bytes long, return it immediatelly.
- if (len >= fast_bytes) {
+ // nice_len long, return it immediatelly.
+ if (len >= nice_len) {
*back_res = i;
*len_res = len;
mf_skip(mf, len - 1);
@@ -94,8 +94,8 @@ lzma_lzma_optimum_fast(lzma_coder *restrict coder, lzma_mf *restrict mf,
}
// We didn't find a long enough repeated match. Encode it as a normal
- // match if the match length is at least fast_bytes.
- if (len_main >= fast_bytes) {
+ // match if the match length is at least nice_len.
+ if (len_main >= nice_len) {
*back_res = coder->matches[matches_count - 1].dist
+ REP_DISTANCES;
*len_res = len_main;
diff --git a/src/liblzma/lzma/lzma_encoder_optimum_normal.c b/src/liblzma/lzma/lzma_encoder_optimum_normal.c
index f0dd92c9..7071a433 100644
--- a/src/liblzma/lzma/lzma_encoder_optimum_normal.c
+++ b/src/liblzma/lzma/lzma_encoder_optimum_normal.c
@@ -281,7 +281,7 @@ helper1(lzma_coder *restrict coder, lzma_mf *restrict mf,
uint32_t *restrict back_res, uint32_t *restrict len_res,
uint32_t position)
{
- const uint32_t fast_bytes = mf->find_len_max;
+ const uint32_t nice_len = mf->nice_len;
uint32_t len_main;
uint32_t matches_count;
@@ -324,7 +324,7 @@ helper1(lzma_coder *restrict coder, lzma_mf *restrict mf,
rep_max_index = i;
}
- if (rep_lens[rep_max_index] >= fast_bytes) {
+ if (rep_lens[rep_max_index] >= nice_len) {
*back_res = rep_max_index;
*len_res = rep_lens[rep_max_index];
mf_skip(mf, *len_res - 1);
@@ -332,7 +332,7 @@ helper1(lzma_coder *restrict coder, lzma_mf *restrict mf,
}
- if (len_main >= fast_bytes) {
+ if (len_main >= nice_len) {
*back_res = coder->matches[matches_count - 1].dist
+ REP_DISTANCES;
*len_res = len_main;
@@ -457,7 +457,7 @@ helper1(lzma_coder *restrict coder, lzma_mf *restrict mf,
static inline uint32_t
helper2(lzma_coder *coder, uint32_t *reps, const uint8_t *buf,
uint32_t len_end, uint32_t position, const uint32_t cur,
- const uint32_t fast_bytes, const uint32_t buf_avail_full)
+ const uint32_t nice_len, const uint32_t buf_avail_full)
{
uint32_t matches_count = coder->matches_count;
uint32_t new_len = coder->longest_match_length;
@@ -572,12 +572,12 @@ helper2(lzma_coder *coder, uint32_t *reps, const uint8_t *buf,
if (buf_avail_full < 2)
return len_end;
- const uint32_t buf_avail = MIN(buf_avail_full, fast_bytes);
+ const uint32_t buf_avail = MIN(buf_avail_full, nice_len);
if (!next_is_literal && match_byte != current_byte) { // speed optimization
// try literal + rep0
const uint8_t *const buf_back = buf - reps[0] - 1;
- const uint32_t limit = MIN(buf_avail_full, fast_bytes + 1);
+ const uint32_t limit = MIN(buf_avail_full, nice_len + 1);
uint32_t len_test = 1;
while (len_test < limit && buf[len_test] == buf_back[len_test])
@@ -656,7 +656,7 @@ helper2(lzma_coder *coder, uint32_t *reps, const uint8_t *buf,
uint32_t len_test_2 = len_test + 1;
const uint32_t limit = MIN(buf_avail_full,
- len_test_2 + fast_bytes);
+ len_test_2 + nice_len);
for (; len_test_2 < limit
&& buf[len_test_2] == buf_back[len_test_2];
++len_test_2) ;
@@ -751,7 +751,7 @@ helper2(lzma_coder *coder, uint32_t *reps, const uint8_t *buf,
const uint8_t *const buf_back = buf - cur_back - 1;
uint32_t len_test_2 = len_test + 1;
const uint32_t limit = MIN(buf_avail_full,
- len_test_2 + fast_bytes);
+ len_test_2 + nice_len);
for (; len_test_2 < limit &&
buf[len_test_2] == buf_back[len_test_2];
@@ -862,11 +862,11 @@ lzma_lzma_optimum_normal(lzma_coder *restrict coder, lzma_mf *restrict mf,
coder->longest_match_length = mf_find(
mf, &coder->matches_count, coder->matches);
- if (coder->longest_match_length >= mf->find_len_max)
+ if (coder->longest_match_length >= mf->nice_len)
break;
len_end = helper2(coder, reps, mf_ptr(mf) - 1, len_end,
- position + cur, cur, mf->find_len_max,
+ position + cur, cur, mf->nice_len,
MIN(mf_avail(mf) + 1, OPTS - 1 - cur));
}
diff --git a/src/liblzma/lzma/lzma_encoder_presets.c b/src/liblzma/lzma/lzma_encoder_presets.c
index 08f339e9..7ef3509e 100644
--- a/src/liblzma/lzma/lzma_encoder_presets.c
+++ b/src/liblzma/lzma/lzma_encoder_presets.c
@@ -20,10 +20,11 @@
#include "common.h"
+/*
#define pow2(e) (UINT32_C(1) << (e))
-LZMA_API const lzma_options_lzma lzma_preset_lzma[9] = {
+static const lzma_options_lzma presets[9] = {
// dict lc lp pb mode fb mf mfc
{ pow2(16), NULL, 0, 3, 0, 2, false, LZMA_MODE_FAST, 64, LZMA_MF_HC3, 0, 0, 0, 0, 0, NULL, NULL },
{ pow2(20), NULL, 0, 3, 0, 0, false, LZMA_MODE_FAST, 64, LZMA_MF_HC4, 0, 0, 0, 0, 0, NULL, NULL },
@@ -37,30 +38,43 @@ LZMA_API const lzma_options_lzma lzma_preset_lzma[9] = {
};
-/*
extern LZMA_API lzma_bool
-lzma_preset_lzma(lzma_options_lzma *options, uint32_t level)
+lzma_lzma_preset(lzma_options_lzma *options, uint32_t level)
{
- *options = (lzma_options_lzma){
+ if (level >= ARRAY_SIZE(presetes))
+ return true;
- };
+ *options = presets[level];
+ return false;
+}
+*/
- options->literal_context_bits = LZMA_LITERAL_CONTEXT_BITS_DEFAULT
- options->literal_pos_bits = LZMA_LITERAL_POS_BITS_DEFAULT;
- options->pos_bits = LZMA_POS_BITS_DEFAULT;
- options->preset_dictionary = NULL;
- options->preset_dictionary_size = 0;
- options->persistent = false;
- options->mode = level <= 2 ? LZMA_MODE_FAST : LZMA_MODE_NORMAL;
- options->fast_bytes = level <=
+extern LZMA_API lzma_bool
+lzma_lzma_preset(lzma_options_lzma *options, uint32_t level)
+{
+ if (level >= 9)
+ return true;
+
+ memzero(options, sizeof(*options));
- options->match_finder = level == 1 ? LZMA_MF_HC3
- : (level == 2 ? LZMA_MF_HC4 : LZMA_MF_BT4);
- options->match_finder_cycles = 0;
+ static const uint8_t shift[9] = { 16, 20, 19, 20, 21, 22, 23, 24, 25 };
+ options->dict_size = UINT32_C(1) << shift[level];
+ options->preset_dict = NULL;
+ options->preset_dict_size = 0;
+ options->lc = LZMA_LC_DEFAULT;
+ options->lp = LZMA_LP_DEFAULT;
+ options->pb = LZMA_PB_DEFAULT;
- options->dictionary_size =
+ options->persistent = false;
+ options->mode = level <= 2 ? LZMA_MODE_FAST : LZMA_MODE_NORMAL;
+
+ options->nice_len = level <= 5 ? 32 : 64;
+ options->mf = level <= 1 ? LZMA_MF_HC3 : level <= 2 ? LZMA_MF_HC4
+ : LZMA_MF_BT4;
+ options->depth = 0;
+
+ return false;
}
-*/