From 2f6f0e84571d420edea04cbd5ffbf0a13934a535 Mon Sep 17 00:00:00 2001 From: Nathan Moinvaziri Date: Wed, 21 Jan 2026 08:51:54 -0800 Subject: Use offset addressing when accessing s->sym_buf. Also optimize sym_next access by caching in local variable --- deflate_p.h | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/deflate_p.h b/deflate_p.h index e9ca871760..ae340f8f37 100644 --- a/deflate_p.h +++ b/deflate_p.h @@ -62,13 +62,16 @@ extern const unsigned char Z_INTERNAL zng_dist_code[]; static inline int zng_tr_tally_lit(deflate_state *s, unsigned char c) { /* c is the unmatched char */ + unsigned int sym_next = s->sym_next; #ifdef LIT_MEM - s->d_buf[s->sym_next] = 0; - s->l_buf[s->sym_next++] = c; + s->d_buf[sym_next] = 0; + s->l_buf[sym_next] = c; + s->sym_next = sym_next + 1; #else - s->sym_buf[s->sym_next++] = 0; - s->sym_buf[s->sym_next++] = 0; - s->sym_buf[s->sym_next++] = c; + s->sym_buf[sym_next] = 0; + s->sym_buf[sym_next+1] = 0; + s->sym_buf[sym_next+2] = c; + s->sym_next = sym_next + 3; #endif s->dyn_ltree[c].Freq++; Tracevv((stderr, "%c", c)); @@ -79,15 +82,18 @@ static inline int zng_tr_tally_lit(deflate_state *s, unsigned char c) { static inline int zng_tr_tally_dist(deflate_state* s, uint32_t dist, uint32_t len) { /* dist: distance of matched string */ /* len: match length-STD_MIN_MATCH */ + unsigned int sym_next = s->sym_next; #ifdef LIT_MEM Assert(dist <= UINT16_MAX, "dist should fit in uint16_t"); Assert(len <= UINT8_MAX, "len should fit in uint8_t"); - s->d_buf[s->sym_next] = (uint16_t)dist; - s->l_buf[s->sym_next++] = (uint8_t)len; + s->d_buf[sym_next] = (uint16_t)dist; + s->l_buf[sym_next] = (uint8_t)len; + s->sym_next = sym_next + 1; #else - s->sym_buf[s->sym_next++] = (uint8_t)(dist); - s->sym_buf[s->sym_next++] = (uint8_t)(dist >> 8); - s->sym_buf[s->sym_next++] = (uint8_t)len; + s->sym_buf[sym_next] = (uint8_t)(dist); + s->sym_buf[sym_next+1] = (uint8_t)(dist >> 8); + s->sym_buf[sym_next+2] = (uint8_t)len; + s->sym_next = sym_next + 3; #endif s->matches++; dist--; -- cgit 0.0.5-2-1-g0f52