From: Willy Tarreau Date: Fri, 1 Apr 2022 15:16:44 +0000 (+0200) Subject: OPTIM: hpack: read 32 bits at once when possible. X-Git-Tag: v2.6-dev5~58 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fcce0e1e093b75b3edf4188fa95bb5a55398478a;p=thirdparty%2Fhaproxy.git OPTIM: hpack: read 32 bits at once when possible. 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. --- diff --git a/src/hpack-huff.c b/src/hpack-huff.c index 9c63e28e83..35fa52d597 100644 --- a/src/hpack-huff.c +++ b/src/hpack-huff.c @@ -31,6 +31,7 @@ #include #include +#include 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 {