]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Optimize inflate_fast for a 0.8% speedup
authorJosh Triplett <josh@joshtriplett.org>
Fri, 14 Aug 2020 03:59:17 +0000 (20:59 -0700)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Sun, 16 Aug 2020 15:35:53 +0000 (17:35 +0200)
When inflate_fast checks for extra length bits, it first checks if the
number of extra length bits (in op) is non-zero. However, if the number
of extra length bits is 0, the `bits < op` check will be false, BITS(op)
will be 0, and DROPBITS(op) will do nothing. So, drop the conditional,
for a speedup of about 0.8%.

This makes the handling of extra length bits match the handling of extra
dist bits, which already lacks the extra conditional.

inffast.c

index 27c29d9ed50fcf4292273ff1f67b365b3be0ec79..2953e09e46845d655ad597eb2815bda352e0cc91 100644 (file)
--- a/inffast.c
+++ b/inffast.c
@@ -171,15 +171,13 @@ void ZLIB_INTERNAL zng_inflate_fast(PREFIX3(stream) *strm, unsigned long start)
         } else if (op & 16) {                     /* length base */
             len = here->val;
             op &= 15;                           /* number of extra bits */
-            if (op) {
-                if (bits < op) {
-                    hold |= load_64_bits(in, bits);
-                    in += 6;
-                    bits += 48;
-                }
-                len += BITS(op);
-                DROPBITS(op);
+            if (bits < op) {
+                hold |= load_64_bits(in, bits);
+                in += 6;
+                bits += 48;
             }
+            len += BITS(op);
+            DROPBITS(op);
             Tracevv((stderr, "inflate:         length %u\n", len));
             if (bits < 15) {
                 hold |= load_64_bits(in, bits);