From e82ee090c567e560f51a056775a17f534d159d65 Mon Sep 17 00:00:00 2001 From: Lasse Collin Date: Tue, 25 Mar 2025 15:18:30 +0200 Subject: [PATCH] liblzma: Define LZ_DICT_INIT_POS for initial dictionary position It's more readable. --- src/liblzma/lz/lz_decoder.c | 4 ++-- src/liblzma/lz/lz_decoder.h | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/liblzma/lz/lz_decoder.c b/src/liblzma/lz/lz_decoder.c index 92913f22..697000d7 100644 --- a/src/liblzma/lz/lz_decoder.c +++ b/src/liblzma/lz/lz_decoder.c @@ -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; diff --git a/src/liblzma/lz/lz_decoder.h b/src/liblzma/lz/lz_decoder.h index cb61b6e2..e432c9e5 100644 --- a/src/liblzma/lz/lz_decoder.h +++ b/src/liblzma/lz/lz_decoder.h @@ -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; }