From 684985a83234a249a947badad446f535e96bf0f0 Mon Sep 17 00:00:00 2001 From: Hans Kristian Rosbach Date: Mon, 18 Aug 2025 20:53:23 +0200 Subject: [PATCH] Use local pointers to avoid indirection penalty in compress_block --- trees.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/trees.c b/trees.c index 9f2f4913..0035e8d7 100644 --- a/trees.c +++ b/trees.c @@ -712,15 +712,24 @@ static void compress_block(deflate_state *s, const ct_data *ltree, const ct_data int lc; /* match length or unmatched char (if dist == 0) */ unsigned sx = 0; /* running index in symbol buffers */ - if (s->sym_next != 0) { + /* Local pointers to avoid indirection */ + const unsigned int sym_next = s->sym_next; +#ifdef LIT_MEM + uint16_t *d_buf = s->d_buf; + unsigned char *l_buf = s->l_buf; +#else + unsigned char *sym_buf = s->sym_buf; +#endif + + if (sym_next != 0) { do { #ifdef LIT_MEM - dist = s->d_buf[sx]; - lc = s->l_buf[sx++]; + dist = d_buf[sx]; + lc = l_buf[sx++]; #else - dist = s->sym_buf[sx++] & 0xff; - dist += (unsigned)(s->sym_buf[sx++] & 0xff) << 8; - lc = s->sym_buf[sx++]; + dist = sym_buf[sx++] & 0xff; + dist += (unsigned)(sym_buf[sx++] & 0xff) << 8; + lc = sym_buf[sx++]; #endif if (dist == 0) { zng_emit_lit(s, ltree, lc); @@ -734,7 +743,7 @@ static void compress_block(deflate_state *s, const ct_data *ltree, const ct_data #else Assert(s->pending < s->lit_bufsize + sx, "pending_buf overflow"); #endif - } while (sx < s->sym_next); + } while (sx < sym_next); } zng_emit_end_block(s, ltree, 0); -- 2.47.3