]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Minor optimization of insert_string template.
authorHans Kristian Rosbach <hk-git@circlestorm.org>
Tue, 18 Aug 2020 16:17:45 +0000 (18:17 +0200)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Fri, 21 Aug 2020 07:46:03 +0000 (09:46 +0200)
insert_string_tpl.h

index 00aad32d87d068cb18fe03c79ffada1b814f9ab0..b37dae26da095a660281da2df19584380e4567c0 100644 (file)
@@ -45,7 +45,7 @@ ZLIB_INTERNAL Pos QUICK_INSERT_STRING(deflate_state *const s, const uint32_t str
     hm = h & s->hash_mask;
 
     head = s->head[hm];
-    if (head != str) {
+    if (LIKELY(head != str)) {
         s->prev[str & s->w_mask] = head;
         s->head[hm] = str;
     }
@@ -61,7 +61,7 @@ ZLIB_INTERNAL Pos QUICK_INSERT_STRING(deflate_state *const s, const uint32_t str
  *    (except for the last MIN_MATCH-1 bytes of the input file).
  */
 ZLIB_INTERNAL Pos INSERT_STRING(deflate_state *const s, const uint32_t str, uint32_t count) {
-    Pos idx, ret = 0;
+    Pos head, idx, ret = 0;
     uint8_t *strstart = s->window + str;
     uint8_t *strend = strstart + count - 1; /* last position */
     uint32_t hash_mask = s->hash_mask;
@@ -81,16 +81,19 @@ ZLIB_INTERNAL Pos INSERT_STRING(deflate_state *const s, const uint32_t str, uint
         UPDATE_HASH(s, h, val);
         hm = h & hash_mask;
 
-        Pos head = s->head[hm];
-        if (head != idx) {
+        head = s->head[hm];
+        if (LIKELY(head != idx)) {
             s->prev[idx & s->w_mask] = head;
             s->head[hm] = idx;
-            if (strstart == strend)
-                ret = head;
-        } else if (strstart == strend) {
-            ret = idx;
         }
     }
+
+    if (strstart == strend) {
+        if (head != idx)
+            ret = head;
+        else
+            ret = idx;
+    }
     return ret;
 }
 #endif