]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
OPTIM: hpack: read 32 bits at once when possible.
authorWilly Tarreau <w@1wt.eu>
Fri, 1 Apr 2022 15:16:44 +0000 (17:16 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 1 Apr 2022 15:29:06 +0000 (17:29 +0200)
As suggested in the comment, it's possible to read 32 bits at once in
big-endian order, and now we have the functions to do this, so let's
do it. This reduces the code on the fast path by 31 bytes on x86, and
more importantly performs single-operation 32-bit reads instead of
playing with shifts and additions.

src/hpack-huff.c

index 9c63e28e839dedec89ef9c28bb79e509755375e0..35fa52d5971cdcca67b20aaaeab4d562ba586baa 100644 (file)
@@ -31,6 +31,7 @@
 
 #include <haproxy/api.h>
 #include <haproxy/hpack-huff.h>
+#include <haproxy/net_helper.h>
 
 struct huff {
        uint32_t c; /* code point */
@@ -1439,17 +1440,11 @@ int huff_dec(const uint8_t *huff, int hlen, char *out, int olen)
                while (shift >= 32) {
                        curr = next;
 
-                       /* read up to 4 bytes into next. FIXME: this should
-                        * later be optimized to perform a single 32-bit big
-                        * endian read when unaligned accesses are possible.
-                        */
+                       /* read up to 4 bytes into next */
                        next = 0;
 
                        if (huff + 4 <= huff_end) {
-                               next =  ((uint32_t)huff[0] << 24) +
-                                       ((uint32_t)huff[1] << 16) +
-                                       ((uint32_t)huff[2] <<  8) +
-                                        (uint32_t)huff[3];
+                               next = read_n32(huff);
                                huff += 4;
                        }
                        else {