]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
liblzma: Define LZ_DICT_INIT_POS for initial dictionary position
authorLasse Collin <lasse.collin@tukaani.org>
Tue, 25 Mar 2025 13:18:30 +0000 (15:18 +0200)
committerLasse Collin <lasse.collin@tukaani.org>
Tue, 25 Mar 2025 13:18:30 +0000 (15:18 +0200)
It's more readable.

src/liblzma/lz/lz_decoder.c
src/liblzma/lz/lz_decoder.h

index 92913f225a0d0ac1c45a83b793773b1640a95cbf..697000d70b836a48c08849201624f3c2f31ca66c 100644 (file)
@@ -53,9 +53,9 @@ typedef struct {
 static void
 lz_decoder_reset(lzma_coder *coder)
 {
-       coder->dict.pos = 2 * LZ_DICT_REPEAT_MAX;
+       coder->dict.pos = LZ_DICT_INIT_POS;
        coder->dict.full = 0;
-       coder->dict.buf[2 * LZ_DICT_REPEAT_MAX - 1] = '\0';
+       coder->dict.buf[LZ_DICT_INIT_POS - 1] = '\0';
        coder->dict.has_wrapped = false;
        coder->dict.need_reset = false;
        return;
index cb61b6e24c78ae7424b166f00fde0a76aedede9d..e432c9e56b72341f84c0fa76d346a9c20660193f 100644 (file)
@@ -35,6 +35,9 @@
 /// LZMA's longest match length is 273 so pick a multiple of 16 above that.
 #define LZ_DICT_REPEAT_MAX 288
 
+/// Initial position in lzma_dict.buf when the dictionary is empty.
+#define LZ_DICT_INIT_POS (2 * LZ_DICT_REPEAT_MAX)
+
 
 typedef struct {
        /// Pointer to the dictionary buffer.
@@ -185,7 +188,7 @@ dict_repeat(lzma_dict *dict, uint32_t distance, uint32_t *len)
 
        // Update how full the dictionary is.
        if (!dict->has_wrapped)
-               dict->full = dict->pos - 2 * LZ_DICT_REPEAT_MAX;
+               dict->full = dict->pos - LZ_DICT_INIT_POS;
 
        return *len != 0;
 }
@@ -197,7 +200,7 @@ dict_put(lzma_dict *dict, uint8_t byte)
        dict->buf[dict->pos++] = byte;
 
        if (!dict->has_wrapped)
-               dict->full = dict->pos - 2 * LZ_DICT_REPEAT_MAX;
+               dict->full = dict->pos - LZ_DICT_INIT_POS;
 }
 
 
@@ -234,7 +237,7 @@ dict_write(lzma_dict *restrict dict, const uint8_t *restrict in,
                        dict->buf, &dict->pos, dict->limit);
 
        if (!dict->has_wrapped)
-               dict->full = dict->pos - 2 * LZ_DICT_REPEAT_MAX;
+               dict->full = dict->pos - LZ_DICT_INIT_POS;
 
        return;
 }