]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Use local pointers to avoid indirection penalty in compress_block
authorHans Kristian Rosbach <hk-git@circlestorm.org>
Mon, 18 Aug 2025 18:53:23 +0000 (20:53 +0200)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Wed, 20 Aug 2025 11:51:48 +0000 (13:51 +0200)
trees.c

diff --git a/trees.c b/trees.c
index 9f2f49137f08a41be5f46fc70e41598cb6dedcab..0035e8d7882c37db402c48b339dd47fb38bec532 100644 (file)
--- 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);