summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Mussared <jim.mussared@gmail.com>2023-06-27 22:03:52 +1000
committerDamien George <damien@micropython.org>2023-07-21 18:57:49 +1000
commit82db9926ed3546fa98e56b8c06936fed21f492aa (patch)
treec1d0dc0bc03e0d47e2a6c6931f12006cc4138e79
parentc4feb806e0df452273b3c19751d8dad39ef8295b (diff)
lib/uzlib/lz77: Always use separate history buffer.
Because we only use the streaming source, this is just extra code size. Saves 64 bytes on PYBV11. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
-rw-r--r--lib/uzlib/lz77.c40
1 files changed, 9 insertions, 31 deletions
diff --git a/lib/uzlib/lz77.c b/lib/uzlib/lz77.c
index 285b4ddf9..1c7a8442c 100644
--- a/lib/uzlib/lz77.c
+++ b/lib/uzlib/lz77.c
@@ -56,13 +56,6 @@ static size_t uzlib_lz77_search_max_match(struct uzlib_lz77_state *state, const
// Compress the given chunk of data.
void uzlib_lz77_compress(struct uzlib_lz77_state *state, const uint8_t *src, unsigned len) {
- bool use_src_as_history = false;
- if (state->hist_buf == NULL) {
- use_src_as_history = true;
- state->hist_buf = (uint8_t *)src;
- state->hist_len = 0;
- }
-
const uint8_t *top = src + len;
while (src < top) {
// Look for a match in the history window.
@@ -77,31 +70,16 @@ void uzlib_lz77_compress(struct uzlib_lz77_state *state, const uint8_t *src, uns
zlib_match(&state->outbuf, match_offset, match_len);
}
- // Advance the history window.
- if (use_src_as_history) {
- // Use src as the history, so advance it.
- state->hist_len += match_len;
- if (state->hist_len > state->hist_max) {
- state->hist_buf += state->hist_len - state->hist_max;
- state->hist_len = state->hist_max;
- }
- src += match_len;
- } else {
- // Push the bytes into the history buffer.
- size_t mask = state->hist_max - 1;
- while (match_len--) {
- uint8_t b = *src++;
- state->hist_buf[(state->hist_start + state->hist_len) & mask] = b;
- if (state->hist_len == state->hist_max) {
- state->hist_start = (state->hist_start + 1) & mask;
- } else {
- ++state->hist_len;
- }
+ // Push the bytes into the history buffer.
+ size_t mask = state->hist_max - 1;
+ while (match_len--) {
+ uint8_t b = *src++;
+ state->hist_buf[(state->hist_start + state->hist_len) & mask] = b;
+ if (state->hist_len == state->hist_max) {
+ state->hist_start = (state->hist_start + 1) & mask;
+ } else {
+ ++state->hist_len;
}
}
}
-
- if (use_src_as_history) {
- state->hist_buf = NULL;
- }
}