]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Minor optimization of insert_string insert_string_opt 1951/head
authorHans Kristian Rosbach <hk-git@circlestorm.org>
Fri, 15 Aug 2025 13:59:46 +0000 (15:59 +0200)
committerHans Kristian Rosbach <hk-git@circlestorm.org>
Sat, 16 Aug 2025 22:18:00 +0000 (00:18 +0200)
insert_string.c
insert_string_tpl.h

index 11a5b97ffe86f37a9f5e9cbd4fd3bd68cc54c378..0c72347fc6af8b7c2bd65bab9c8d1d956bebbfff 100644 (file)
@@ -12,7 +12,7 @@
 
 #define HASH_CALC(h, val)    h = ((val * 2654435761U) >> HASH_SLIDE);
 #define HASH_CALC_VAR        h
-#define HASH_CALC_VAR_INIT   uint32_t h = 0
+#define HASH_CALC_VAR_INIT   uint32_t h
 
 #define UPDATE_HASH          update_hash
 #define INSERT_STRING        insert_string
index 1548ca741ad19b5ac8346e39cebc1b80016f9a03..2e1fa63d15f97d9c90cbbe5bd205d282975ff704 100644 (file)
@@ -57,9 +57,9 @@ Z_INTERNAL uint32_t UPDATE_HASH(uint32_t h, uint32_t val) {
  * the previous length of the hash chain.
  */
 Z_INTERNAL Pos QUICK_INSERT_STRING(deflate_state *const s, uint32_t str) {
-    Pos head;
     uint8_t *strstart = s->window + str + HASH_CALC_OFFSET;
     uint32_t val, hm;
+    Pos head;
 
     HASH_CALC_VAR_INIT;
     HASH_CALC_READ;
@@ -86,6 +86,9 @@ Z_INTERNAL Pos QUICK_INSERT_STRING(deflate_state *const s, uint32_t str) {
 Z_INTERNAL void INSERT_STRING(deflate_state *const s, uint32_t str, uint32_t count) {
     uint8_t *strstart = s->window + str + HASH_CALC_OFFSET;
     uint8_t *strend = strstart + count;
+    Pos *headp = s->head;
+    Pos *prevp = s->prev;
+    const unsigned int w_mask = s->w_mask;
 
     for (Pos idx = (Pos)str; strstart < strend; idx++, strstart++) {
         uint32_t val, hm;
@@ -96,10 +99,10 @@ Z_INTERNAL void INSERT_STRING(deflate_state *const s, uint32_t str, uint32_t cou
         HASH_CALC_VAR &= HASH_CALC_MASK;
         hm = HASH_CALC_VAR;
 
-        Pos head = s->head[hm];
+        Pos head = headp[hm];
         if (LIKELY(head != idx)) {
-            s->prev[idx & s->w_mask] = head;
-            s->head[hm] = idx;
+            prevp[idx & w_mask] = head;
+            headp[hm] = idx;
         }
     }
 }