diff options
| author | Nathan Moinvaziri <nathan@nathanm.com> | 2026-01-21 08:51:54 -0800 |
|---|---|---|
| committer | Hans Kristian Rosbach <hk-github@circlestorm.org> | 2026-02-18 13:57:07 +0100 |
| commit | 2f6f0e84571d420edea04cbd5ffbf0a13934a535 (patch) | |
| tree | 6e1394e67969359eb3e8d0ff9624272f74699725 | |
| parent | 5fd8b67c1a586302106606b2be3c784fb6dc2124 (diff) | |
| download | Project-Tick-2f6f0e84571d420edea04cbd5ffbf0a13934a535.tar.gz Project-Tick-2f6f0e84571d420edea04cbd5ffbf0a13934a535.zip | |
Use offset addressing when accessing s->sym_buf.
Also optimize sym_next access by caching in local variable
| -rw-r--r-- | deflate_p.h | 26 |
1 files 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--; |
