aboutsummaryrefslogtreecommitdiff
path: root/src/liblzma/lz
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/lz
parentAdded 7z2lzma.bash. (diff)
downloadxz-1dcecfb09b55157b8653d747963069c8bed74f04.tar.xz
Some API changes, bug fixes, cleanups etc.
Diffstat (limited to 'src/liblzma/lz')
-rw-r--r--src/liblzma/lz/lz_encoder.c30
-rw-r--r--src/liblzma/lz/lz_encoder.h26
-rw-r--r--src/liblzma/lz/lz_encoder_mf.c30
3 files changed, 42 insertions, 44 deletions
diff --git a/src/liblzma/lz/lz_encoder.c b/src/liblzma/lz/lz_encoder.c
index 159080ee..d598f71a 100644
--- a/src/liblzma/lz/lz_encoder.c
+++ b/src/liblzma/lz/lz_encoder.c
@@ -189,15 +189,13 @@ lz_encoder_prepare(lzma_mf *mf, lzma_allocator *allocator,
// For now, the dictionary size is limited to 1.5 GiB. This may grow
// in the future if needed, but it needs a little more work than just
// changing this check.
- if (lz_options->dictionary_size < LZMA_DICTIONARY_SIZE_MIN
- || lz_options->dictionary_size
+ if (lz_options->dict_size < LZMA_DICT_SIZE_MIN
+ || lz_options->dict_size
> (UINT32_C(1) << 30) + (UINT32_C(1) << 29)
- || lz_options->find_len_max
- > lz_options->match_len_max)
+ || lz_options->nice_len > lz_options->match_len_max)
return true;
- mf->keep_size_before = lz_options->before_size
- + lz_options->dictionary_size;
+ mf->keep_size_before = lz_options->before_size + lz_options->dict_size;
mf->keep_size_after = lz_options->after_size
+ lz_options->match_len_max;
@@ -213,7 +211,7 @@ lz_encoder_prepare(lzma_mf *mf, lzma_allocator *allocator,
// to size_t.
// - Memory usage calculation needs something too, e.g. use uint64_t
// for mf->size.
- uint32_t reserve = lz_options->dictionary_size / 2;
+ uint32_t reserve = lz_options->dict_size / 2;
if (reserve > (UINT32_C(1) << 30))
reserve /= 2;
@@ -232,7 +230,7 @@ lz_encoder_prepare(lzma_mf *mf, lzma_allocator *allocator,
// Match finder options
mf->match_len_max = lz_options->match_len_max;
- mf->find_len_max = lz_options->find_len_max;
+ mf->nice_len = lz_options->nice_len;
// cyclic_size has to stay smaller than 2 Gi. Note that this doesn't
// mean limitting dictionary size to less than 2 GiB. With a match
@@ -249,7 +247,7 @@ lz_encoder_prepare(lzma_mf *mf, lzma_allocator *allocator,
// memory to keep the code simpler. The current way is simple and
// still allows pretty big dictionaries, so I don't expect these
// limits to change.
- mf->cyclic_size = lz_options->dictionary_size + 1;
+ mf->cyclic_size = lz_options->dict_size + 1;
// Validate the match finder ID and setup the function pointers.
switch (lz_options->match_finder) {
@@ -289,9 +287,9 @@ lz_encoder_prepare(lzma_mf *mf, lzma_allocator *allocator,
}
// Calculate the sizes of mf->hash and mf->son and check that
- // find_len_max is big enough for the selected match finder.
+ // nice_len is big enough for the selected match finder.
const uint32_t hash_bytes = lz_options->match_finder & 0x0F;
- if (hash_bytes > mf->find_len_max)
+ if (hash_bytes > mf->nice_len)
return true;
const bool is_bt = (lz_options->match_finder & 0x10) != 0;
@@ -302,7 +300,7 @@ lz_encoder_prepare(lzma_mf *mf, lzma_allocator *allocator,
} else {
// Round dictionary size up to the next 2^n - 1 so it can
// be used as a hash mask.
- hs = lz_options->dictionary_size - 1;
+ hs = lz_options->dict_size - 1;
hs |= hs >> 1;
hs |= hs >> 2;
hs |= hs >> 4;
@@ -353,11 +351,11 @@ lz_encoder_prepare(lzma_mf *mf, lzma_allocator *allocator,
}
// Maximum number of match finder cycles
- mf->loops = lz_options->match_finder_cycles;
- if (mf->loops == 0) {
- mf->loops = 16 + (mf->find_len_max / 2);
+ mf->depth = lz_options->depth;
+ if (mf->depth == 0) {
+ mf->depth = 16 + (mf->nice_len / 2);
if (!is_bt)
- mf->loops /= 2;
+ mf->depth /= 2;
}
return false;
diff --git a/src/liblzma/lz/lz_encoder.h b/src/liblzma/lz/lz_encoder.h
index 373cc01b..44880d77 100644
--- a/src/liblzma/lz/lz_encoder.h
+++ b/src/liblzma/lz/lz_encoder.h
@@ -110,13 +110,13 @@ struct lzma_mf_s {
uint32_t hash_mask;
/// Maximum number of loops in the match finder
- uint32_t loops;
+ uint32_t depth;
/// Maximum length of a match that the match finder will try to find.
- uint32_t find_len_max;
+ uint32_t nice_len;
/// Maximum length of a match supported by the LZ-based encoder.
- /// If the longest match found by the match finder is find_len_max,
+ /// If the longest match found by the match finder is nice_len,
/// mf_find() tries to expand it up to match_len_max bytes.
uint32_t match_len_max;
@@ -139,40 +139,40 @@ typedef struct {
size_t before_size;
/// Size of the history buffer
- size_t dictionary_size;
+ size_t dict_size;
/// Extra amount of data to keep available after the "actual"
/// dictionary.
size_t after_size;
/// Maximum length of a match that the LZ-based encoder can accept.
- /// This is used to extend matches of length find_len_max to the
+ /// This is used to extend matches of length nice_len to the
/// maximum possible length.
size_t match_len_max;
/// Match finder will search matches of at maximum of this length.
/// This must be less than or equal to match_len_max.
- size_t find_len_max;
+ size_t nice_len;
/// Type of the match finder to use
lzma_match_finder match_finder;
- /// TODO: Comment
- uint32_t match_finder_cycles;
+ /// Maximum search depth
+ uint32_t depth;
/// TODO: Comment
- const uint8_t *preset_dictionary;
+ const uint8_t *preset_dict;
- uint32_t preset_dictionary_size;
+ uint32_t preset_dict_size;
} lzma_lz_options;
// The total usable buffer space at any moment outside the match finder:
-// before_size + dictionary_size + after_size + match_len_max
+// before_size + dict_size + after_size + match_len_max
//
// In reality, there's some extra space allocated to prevent the number of
-// memmove() calls reasonable. The bigger the dictionary_size is, the bigger
+// memmove() calls reasonable. The bigger the dict_size is, the bigger
// this extra buffer will be since with bigger dictionaries memmove() would
// also take longer.
//
@@ -181,7 +181,7 @@ typedef struct {
// In other words, a single encoder loop may advance lzma_mf.read_pos at
// maximum of after_size times. Since matches are looked up to
// lzma_mf.buffer[lzma_mf.read_pos + match_len_max - 1], the total
-// amount of extra buffer needed after dictionary_size becomes
+// amount of extra buffer needed after dict_size becomes
// after_size + match_len_max.
//
// before_size has two uses. The first one is to keep literals available
diff --git a/src/liblzma/lz/lz_encoder_mf.c b/src/liblzma/lz/lz_encoder_mf.c
index d82681b3..9d50e91d 100644
--- a/src/liblzma/lz/lz_encoder_mf.c
+++ b/src/liblzma/lz/lz_encoder_mf.c
@@ -42,7 +42,7 @@ lzma_mf_find(lzma_mf *mf, uint32_t *count_ptr, lzma_match *matches)
#ifndef NDEBUG
// Validate the matches.
for (uint32_t i = 0; i < count; ++i) {
- assert(matches[i].len <= mf->find_len_max);
+ assert(matches[i].len <= mf->nice_len);
assert(matches[i].dist < mf->read_pos);
assert(memcmp(mf_ptr(mf) - 1,
mf_ptr(mf) - matches[i].dist - 2,
@@ -56,7 +56,7 @@ lzma_mf_find(lzma_mf *mf, uint32_t *count_ptr, lzma_match *matches)
// If a match of maximum search length was found, try to
// extend the match to maximum possible length.
- if (len_best == mf->find_len_max) {
+ if (len_best == mf->nice_len) {
// The limit for the match length is either the
// maximum match length supported by the LZ-based
// encoder or the number of bytes left in the
@@ -90,7 +90,7 @@ lzma_mf_find(lzma_mf *mf, uint32_t *count_ptr, lzma_match *matches)
/// Hash value to indicate unused element in the hash. Since we start the
-/// positions from dictionary_size + 1, zero is always too far to qualify
+/// positions from dict_size + 1, zero is always too far to qualify
/// as usable match position.
#define EMPTY_HASH_VALUE 0
@@ -166,7 +166,7 @@ move_pos(lzma_mf *mf)
}
-/// When flushing, we cannot run the match finder unless there is find_len_max
+/// When flushing, we cannot run the match finder unless there is nice_len
/// bytes available in the dictionary. Instead, we skip running the match
/// finder (indicating that no match was found), and count how many bytes we
/// have ignored this way.
@@ -196,8 +196,8 @@ move_pending(lzma_mf *mf)
/// in them.
#define header(is_bt, len_min, ret_op) \
uint32_t len_limit = mf_avail(mf); \
- if (mf->find_len_max <= len_limit) { \
- len_limit = mf->find_len_max; \
+ if (mf->nice_len <= len_limit) { \
+ len_limit = mf->nice_len; \
} else if (len_limit < (len_min) \
|| (is_bt && mf->action == LZMA_SYNC_FLUSH)) { \
assert(mf->action != LZMA_RUN); \
@@ -226,7 +226,7 @@ move_pending(lzma_mf *mf)
/// of matches found.
#define call_find(func, len_best) \
do { \
- matches_count = func(len_limit, pos, cur, cur_match, mf->loops, \
+ matches_count = func(len_limit, pos, cur, cur_match, mf->depth, \
mf->son, mf->cyclic_pos, mf->cyclic_size, \
matches + matches_count, len_best) \
- matches; \
@@ -246,7 +246,7 @@ do { \
/// \param pos lzma_mf.read_pos + lzma_mf.offset
/// \param cur Pointer to current byte (mf_ptr(mf))
/// \param cur_match Start position of the current match candidate
-/// \param loops Maximum length of the hash chain
+/// \param depth Maximum length of the hash chain
/// \param son lzma_mf.son (contains the hash chain)
/// \param cyclic_pos
/// \param cyclic_size
@@ -258,7 +258,7 @@ hc_find_func(
const uint32_t pos,
const uint8_t *const cur,
uint32_t cur_match,
- uint32_t loops,
+ uint32_t depth,
uint32_t *const son,
const uint32_t cyclic_pos,
const uint32_t cyclic_size,
@@ -269,7 +269,7 @@ hc_find_func(
while (true) {
const uint32_t delta = pos - cur_match;
- if (loops-- == 0 || delta >= cyclic_size)
+ if (depth-- == 0 || delta >= cyclic_size)
return matches;
const uint8_t *const pb = cur - delta;
@@ -463,7 +463,7 @@ bt_find_func(
const uint32_t pos,
const uint8_t *const cur,
uint32_t cur_match,
- uint32_t loops,
+ uint32_t depth,
uint32_t *const son,
const uint32_t cyclic_pos,
const uint32_t cyclic_size,
@@ -478,7 +478,7 @@ bt_find_func(
while (true) {
const uint32_t delta = pos - cur_match;
- if (loops-- == 0 || delta >= cyclic_size) {
+ if (depth-- == 0 || delta >= cyclic_size) {
*ptr0 = EMPTY_HASH_VALUE;
*ptr1 = EMPTY_HASH_VALUE;
return matches;
@@ -531,7 +531,7 @@ bt_skip_func(
const uint32_t pos,
const uint8_t *const cur,
uint32_t cur_match,
- uint32_t loops,
+ uint32_t depth,
uint32_t *const son,
const uint32_t cyclic_pos,
const uint32_t cyclic_size)
@@ -544,7 +544,7 @@ bt_skip_func(
while (true) {
const uint32_t delta = pos - cur_match;
- if (loops-- == 0 || delta >= cyclic_size) {
+ if (depth-- == 0 || delta >= cyclic_size) {
*ptr0 = EMPTY_HASH_VALUE;
*ptr1 = EMPTY_HASH_VALUE;
return;
@@ -588,7 +588,7 @@ bt_skip_func(
#define bt_skip() \
do { \
- bt_skip_func(len_limit, pos, cur, cur_match, mf->loops, \
+ bt_skip_func(len_limit, pos, cur, cur_match, mf->depth, \
mf->son, mf->cyclic_pos, \
mf->cyclic_size); \
move_pos(mf); \